MongoDB
Basic command
Run MongoDB Community Edition
Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.
You can run MongoDB as a macOS service using brew, or you can run MongoDB manually as a background process. It is recommended to run MongoDB as a macOS service, as doing so sets the correct system ulimit values automatically (see ulimit settings for more information).
To run MongoDB (i.e. the mongod process) as a macOS service, run:
brew services start mongodb-community@5.0
To stop a mongod running as a macOS service, use the following command as needed:
brew services stop mongodb-community@5.0
Use
command line
use command:
mongo
or better
mongosh
usage statistic:
mongotop
Create
User
db.createUser({user: "AmazonScrapper", pwd: "xxxxxxx", roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]})
Search
Simple search
everything
db.getCollection('amazondatas').find({})
exact field
db.getCollection('amazondatas').find({name:"Tenet [Blu-Ray]"})
Search with create query
For text search on multi field, index is needed. name/description are field of the wanted searchable document.
create index
db.amazondatas.createIndex( {name: "text", price: 1})
Find query
by every text field
to search on the previous index, on every text field referenced
db.amazondatas.find( { $text: { $search: "java coffee shop" } } )
by exact phrase
db.amazondatas.find( { $text: { $search: "\"coffee shop\"" } } )
with exlusion
db.amazondatas.find( { $text: { $search: "java shop -coffee" } } )
sorting
db.amazondatas.find(
{ $text: { $search: "java coffee shop" } },
{ score: { $meta: "textScore" } }
).sort( { score: { $meta: "textScore" } } )
Children
Backlinks