docker run --name mongo -d mongo
docker exec -it mongo bash
Note: run this command inside mongo container.
mongosh
db.createCollection('COLLECTION_NAME')
db.COLLECTION_NAME.insert({ 'any_key': 'any_value' })
db.COLLECTION_NAME.find()
Or
db.COLLECTION_NAME.find().pretty()
db.COLLECTION_NAME.remove({
'_id': ObjectId('ITEM_ID')
})
db.COLLECTION_NAME.find({
any_key: 'any_value'
})
Or
db.COLLECTION_NAME.find({
'any_key_1.any_key_2': 'any_value'
})
Or
db.COLLECTION_NAME.find({
$or: [
{ 'any_key_1.any_key_2': 'any_value_1' },
{ 'any_key_1.any_key_2': 'any_value_2' }
]
})
Or
db.COLLECTION_NAME.find({
'any_key_1.any_key_2': {
$in: ['any_value_1', 'any_key_2']
}
})
Or
db.COLLECTION_NAME.find({
'any_key_1.any_key_2': {
$gt: 'any_value_1'
}
})
db.COLLECTION_NAME.findOne({
any_key: 'any_value'
})
db.COLLECTION_NAME.find({
any_key: 'any_value'
}).sort({ any_key: 1 }) # 1 for asc and -1 for desc
db.COLLECTION_NAME.find({
any_key: 'any_value'
}).limit(ANY_LIMIT)
db.COLLECTION_NAME.update(
{ any_key: 'any_value' }, # query
{ ... } # item data
)
Or
db.COLLECTION_NAME.update(
{ any_key: 'any_value' }, # query
{
$set: {
... # item data
}
}
)
Or
db.COLLECTION_NAME.update(
{ any_key: 'any_value' }, # query
{
$set: {
... # item data
}
},
{
multi: true
}
)