2018-04-16T17:33:20.754+0800 E QUERY [thread1] SyntaxError: missing : after property id @(shell):1:23
> db.runoob.insert({"name":"hello world"})
WriteResult({ "nInserted" : 1 })
> show dbs
admin 0.000GB
local 0.000GB
mymongo 0.000GB
text 0.000GB
text2 0.000GB
> use text2
switched to db text2
> db.dropDatabase()
{ "dropped" : "text2", "ok" : 1 }
> use mymongo
switched to db mymongo
> db.tables
mymongo.tables
> db.createCollection("myColle")
{ "ok" : 1 }
> show collections
myColle
runoob
> db.createCollections("collect",{capped:true,autoIndexId:true,size:6142800,max:10000}
... )
2018-04-16T17:40:41.507+0800 E QUERY [thread1] TypeError: db.createCollections is not a function :
@(shell):1:1
> db.createCollection("collect",{capped:true,autoIndexId:true,size:6142800,max:10000} )
{
"note" : "the autoIndexId option is deprecated and will be removed in a future release",
"ok" : 1
}
> show collections
collect
myColle
runoob
> db.collect.drop()
true
> db.myColle.find()
> db.myColle.insert({"title":"tieleval","name":"nameval"})
WriteResult({ "nInserted" : 1 })
> db.myColle.find()
{ "_id" : ObjectId("5ad47848f96e28a6002a2a26"), "title" : "tieleval", "name" : "nameval" }
> db.myColle.insert({"title":"tieleval","name":"nameval2"})
WriteResult({ "nInserted" : 1 })
> db.myColle.find()
{ "_id" : ObjectId("5ad47848f96e28a6002a2a26"), "title" : "tieleval", "name" : "nameval" }
{ "_id" : ObjectId("5ad47b68f96e28a6002a2a27"), "title" : "tieleval", "name" : "nameval2" }
> db.myColle.update({"title":"nameval1"},{$set:{"title":"tieleval"}})
WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
> db.myColle.update({"name":"nameval"},{$set:{"name":"nameval1"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.myColle.find()
{ "_id" : ObjectId("5ad47848f96e28a6002a2a26"), "title" : "tieleval", "name" : "nameval1" }
{ "_id" : ObjectId("5ad47b68f96e28a6002a2a27"), "title" : "tieleval", "name" : "nameval2" }
> db.myColle.find().pretty()
{
"_id" : ObjectId("5ad47848f96e28a6002a2a26"),
"title" : "tieleval",
"name" : "nameval1"
}
{
"_id" : ObjectId("5ad47b68f96e28a6002a2a27"),
"title" : "tieleval",
"name" : "nameval2"
}
> db.myColle.insert({"title":"tieleval","name":"nameval3"})
WriteResult({ "nInserted" : 1 })
> db.myColle.update({"title":"tieleval"},{$.set:{"title":"titleVal"}},{multi:true})
2018-04-16T18:36:25.038+0800 E QUERY [thread1] SyntaxError: missing : after property id @(shell):1:41
> db.myColle.update({"title":"tieleval"},{$set:{"title":"titleVal"}},{multi:true})
WriteResult({ "nMatched" : 3, "nUpserted" : 0, "nModified" : 3 })
> db.myColle.find().pretty()
{
"_id" : ObjectId("5ad47848f96e28a6002a2a26"),
"title" : "titleVal",
"name" : "nameval1"
}
{
"_id" : ObjectId("5ad47b68f96e28a6002a2a27"),
"title" : "titleVal",
"name" : "nameval2"
}
{
"_id" : ObjectId("5ad47c54f96e28a6002a2a28"),
"title" : "titleVal",
"name" : "nameval3"
}
> db.myColle.remove({"name":"nameval1"})
WriteResult({ "nRemoved" : 1 })
> db.myColle.find().pretty()
{
"_id" : ObjectId("5ad47b68f96e28a6002a2a27"),
"title" : "titleVal",
"name" : "nameval2"
}
{
"_id" : ObjectId("5ad47c54f96e28a6002a2a28"),
"title" : "titleVal",
"name" : "nameval3"
}
> db.myColle.find({"title":"titleVal"})
{ "_id" : ObjectId("5ad47b68f96e28a6002a2a27"), "title" : "titleVal", "name" : "nameval2" }
{ "_id" : ObjectId("5ad47c54f96e28a6002a2a28"), "title" : "titleVal", "name" : "nameval3" }
> db.myColle.find({"name":"nameVal2"})
> db.myColle.find({"name":"nameval2"})
{ "_id" : ObjectId("5ad47b68f96e28a6002a2a27"), "title" : "titleVal", "name" : "nameval2" }
> db.myColle.insert({"int":2})
WriteResult({ "nInserted" : 1 })
> db.myColle.insert({"int":1})
WriteResult({ "nInserted" : 1 })
> db.myColle.insert({"int":3})
WriteResult({ "nInserted" : 1 })
> db.myColle.insert({"int":4})
WriteResult({ "nInserted" : 1 })
> db.myColle.find().pretty()
{
"_id" : ObjectId("5ad47b68f96e28a6002a2a27"),
"title" : "titleVal",
"name" : "nameval2"
}
{
"_id" : ObjectId("5ad47c54f96e28a6002a2a28"),
"title" : "titleVal",
"name" : "nameval3"
}
{ "_id" : ObjectId("5ad4a2adf96e28a6002a2a29"), "int" : 2 }
{ "_id" : ObjectId("5ad4a2b1f96e28a6002a2a2a"), "int" : 1 }
{ "_id" : ObjectId("5ad4a2b4f96e28a6002a2a2b"), "int" : 3 }
{ "_id" : ObjectId("5ad4a2b7f96e28a6002a2a2c"), "int" : 4 }
> db.myColle.find({"int":$lt:2}).pretty()
2018-04-16T21:19:54.858+0800 E QUERY [thread1] SyntaxError: missing } after property list @(shell):1:26
> db.myColle.find({"int":{$lt:2}}).pretty()
{ "_id" : ObjectId("5ad4a2b1f96e28a6002a2a2a"), "int" : 1 }
> db.myColle.find({"int":{$lte:2}}).pretty()
{ "_id" : ObjectId("5ad4a2adf96e28a6002a2a29"), "int" : 2 }
{ "_id" : ObjectId("5ad4a2b1f96e28a6002a2a2a"), "int" : 1 }
> db.myColle.find({"int":{$gte:2}}).pretty()
{ "_id" : ObjectId("5ad4a2adf96e28a6002a2a29"), "int" : 2 }
{ "_id" : ObjectId("5ad4a2b4f96e28a6002a2a2b"), "int" : 3 }
{ "_id" : ObjectId("5ad4a2b7f96e28a6002a2a2c"), "int" : 4 }
> db.myColle.find({"int":{$gt:2}}).pretty()
{ "_id" : ObjectId("5ad4a2b4f96e28a6002a2a2b"), "int" : 3 }
{ "_id" : ObjectId("5ad4a2b7f96e28a6002a2a2c"), "int" : 4 }
> db.myColle.find({"int":{$ne:2}}).pretty()
{
"_id" : ObjectId("5ad47b68f96e28a6002a2a27"),
"title" : "titleVal",
"name" : "nameval2"
}
{
"_id" : ObjectId("5ad47c54f96e28a6002a2a28"),
"title" : "titleVal",
"name" : "nameval3"
}
{ "_id" : ObjectId("5ad4a2b1f96e28a6002a2a2a"), "int" : 1 }
{ "_id" : ObjectId("5ad4a2b4f96e28a6002a2a2b"), "int" : 3 }
{ "_id" : ObjectId("5ad4a2b7f96e28a6002a2a2c"), "int" : 4 }
> db.myColle.find({"int":1},{"int":3}).pretty()
{ "_id" : ObjectId("5ad4a2b1f96e28a6002a2a2a"), "int" : 1 }
> db.myColle.find({"int":1 , "int":3}).pretty()
{ "_id" : ObjectId("5ad4a2b4f96e28a6002a2a2b"), "int" : 3 }
> db.myColle.find({$or:[{"int":1},{"int":2}]}).pretty()
{ "_id" : ObjectId("5ad4a2adf96e28a6002a2a29"), "int" : 2 }
{ "_id" : ObjectId("5ad4a2b1f96e28a6002a2a2a"), "int" : 1 }
> db.myColle.find({$or:[{"int":1},{"int":2}]}).pretty().limit(1)
{ "_id" : ObjectId("5ad4a2adf96e28a6002a2a29"), "int" : 2 }
> db.myColle.find({$or:[{"int":1},{"int":2}]}).pretty().limit(1).skip(0)
{ "_id" : ObjectId("5ad4a2adf96e28a6002a2a29"), "int" : 2 }
> db.myColle.find({$or:[{"int":1},{"int":2}]}).pretty().limit(1).skip(1)
{ "_id" : ObjectId("5ad4a2b1f96e28a6002a2a2a"), "int" : 1 }
> db.myColle.find({$or:[{"int":1},{"int":2}]}).sort(int:1)
2018-04-16T21:35:25.076+0800 E QUERY [thread1] SyntaxError: missing ) after argument list @(shell):1:53
> db.myColle.find({$or:[{"int":1},{"int":2}]}).sort("int":1)
2018-04-16T21:35:35.080+0800 E QUERY [thread1] SyntaxError: missing ) after argument list @(shell):1:55
> db.myColle.find({$or:[{"int":1},{"int":2}]}).sort({"int":1})
{ "_id" : ObjectId("5ad4a2b1f96e28a6002a2a2a"), "int" : 1 }
{ "_id" : ObjectId("5ad4a2adf96e28a6002a2a29"), "int" : 2 }
> db.myColle.find({$or:[{"int":1},{"int":2}]}).sort({"int":-1})
{ "_id" : ObjectId("5ad4a2adf96e28a6002a2a29"), "int" : 2 }
{ "_id" : ObjectId("5ad4a2b1f96e28a6002a2a2a"), "int" : 1 }
> db.myColle.ensureIndex({"int":1})
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.myColle.find()
{ "_id" : ObjectId("5ad47b68f96e28a6002a2a27"), "title" : "titleVal", "name" : "nameval2" }
{ "_id" : ObjectId("5ad47c54f96e28a6002a2a28"), "title" : "titleVal", "name" : "nameval3" }
{ "_id" : ObjectId("5ad4a2adf96e28a6002a2a29"), "int" : 2 }
{ "_id" : ObjectId("5ad4a2b1f96e28a6002a2a2a"), "int" : 1 }
{ "_id" : ObjectId("5ad4a2b4f96e28a6002a2a2b"), "int" : 3 }
{ "_id" : ObjectId("5ad4a2b7f96e28a6002a2a2c"), "int" : 4 }
> db.myColle.ensureIndex({"open:1,close:1"},{background:true})
2018-04-16T21:39:08.923+0800 E QUERY [thread1] SyntaxError: missing : after property id @(shell):1:40
> db.myColle.ensureIndex({open:1,close:1},{background:true})
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 2,
"numIndexesAfter" : 3,
"ok" : 1
}
> db.myColle.find()
{ "_id" : ObjectId("5ad47b68f96e28a6002a2a27"), "title" : "titleVal", "name" : "nameval2" }
{ "_id" : ObjectId("5ad47c54f96e28a6002a2a28"), "title" : "titleVal", "name" : "nameval3" }
{ "_id" : ObjectId("5ad4a2adf96e28a6002a2a29"), "int" : 2 }
{ "_id" : ObjectId("5ad4a2b1f96e28a6002a2a2a"), "int" : 1 }
{ "_id" : ObjectId("5ad4a2b4f96e28a6002a2a2b"), "int" : 3 }
{ "_id" : ObjectId("5ad4a2b7f96e28a6002a2a2c"), "int" : 4 }
> db.myColle.insert({"title":"tieleval2","name":"nameval"})
WriteResult({ "nInserted" : 1 })
> db.myColle.insert({"title":"tieleval2","name":"nameval2"})
WriteResult({ "nInserted" : 1 })
> db.myColle.insert({"title":"tieleval2","name":"nameval23"})
WriteResult({ "nInserted" : 1 })
> db.myColle.insert({"title":"tieleval2","name":"nameval234"})
WriteResult({ "nInserted" : 1 })
> db.myColle.insert({"title":"tieleval3","name":"nameval234"})
WriteResult({ "nInserted" : 1 })
> db.myColle.aggreagate([{$group:{_id:"$title",num:{$sum:1}}}])
2018-04-16T21:43:06.488+0800 E QUERY [thread1] TypeError: db.myColle.aggreagate is not a function :
@(shell):1:1
> db.myColle.aggregate([{$group:{_id:"$title",num:{$sum:1}}}])
{ "_id" : "tieleval3", "num" : 1 }
{ "_id" : "tieleval2", "num" : 4 }
{ "_id" : null, "num" : 4 }
{ "_id" : "titleVal", "num" : 2 }
C:\Users\imaye>mongod.exe --port 28012 --dbpath F:\Mongo\text1\data\db1 --keyFile F:\Mongo\text1\key\key1.txt --logpath F:\Mongo\text1\log\log1.txt --logappend --replSet rs
C:\Users\imaye>mongod.exe --port 28013 --dbpath F:\Mongo\text1\data\db1 --keyFile F:\Mongo\text1\key\key1.txt --logpath F:\Mongo\text1\log\log1.txt --logappend --replSet rs
C:\Users\imaye>mongod.exe --port 28014 --dbpath F:\Mongo\text1\data\db2 --keyFile F:\Mongo\text1\key\key2.txt --logpath F:\Mongo\text1\log\log2.txt --logappend --replSet rs