{"greeting" : "Hello world!"}
{"greeting" : "Hello world!", "views" : 3}
{"greeting" : "Hello world!", "views": 3}
{"signoff": "Good bye"}
$ mongod
$ mongo
MongoDB shell version: 4.2.0
connecting to: test
>
> x = 100;
200
> x / 5;
20
{
"_id" : ObjectId("4b2b9f67a1f631733d917a7a"),
"name" : "alice",
"friends" : 24,
"enemies" : 2
}
> db.books.deleteOne({"_id" : 3})
> db.users.find({"age" : 24})
{"x" : null}
{"x" : true}
{"x" : 4}
{"x" : "foobar"}
{"x" : new Date()}
{"x" : /foobar/i}
{"x" : ["a", "b", "c"]}
{"x" : {"foo" : "bar"}}
{"x" : ObjectId()}
{"x" : function() { /* ... */ }}
> db.users.find({"username" : "alice"})
createIndex
collection method.> db.users.find({"username": "user101"}).explain("executionStats")
executionStats
mode helps us understand the effect of using an index to satisfy queries.{
"name" : "New York City",
"loc" : {
"type" : "Point",
"coordinates" : [50, 2]
}
}
{
"name" : "Hudson River",
"loc" : {
"type" : "LineString",
"coordinates" : [[0,1], [0,2], [1,2]]
}
}
> db.users.findOne()
{
"_id" : ObjectId("4b253b067525f35f94b60a31"),
"name" : "alice",
"age" : 23,
"sex" : "female",
"location" : "India"
}
$set
” :> db.users.updateOne({"_id" :
ObjectId("4b253b067525f35f94b60a31")},
... {"$set" : {"favorite book" : "Start with Why"}})
C, C++, C#, Java, Node.js, Perl, PHP, Python, Ruby, Scala, Go
and Erlang
. MongoDB can easily be used with any of these languages. There are some other community supported drivers too but the above mentioned ones are officially provided by MongoDB. >db.COLLECTION_NAME.find().sort({KEY:1})
use [database];
db.dropDatabase();
Ruby code should be pretty similiar.
Also, from the command line:
mongo [Database] -eval "db.dropDatabase();"
use
[databaseName]
db.Drop+databasename();
drop colllection
use databaseName
db.collectionName.drop();
db.COLLECTION_NAME.find({},);
db.COLLECTION_NAME.find().limit(NUMBER);
db.collection.mapReduce(
function() {emit(key,value);},
function(key, values) {return aggregatedResult}, { out: collection }
</pre.
)
C: MongoDB
”