D:\\mongodb-win32-i386-2.0.2\\bin>mongod.exe --dbpath C:\\data\\db
D:\\mongodb-win32-i386-2.0.2\\bin>mongo.exe
MongoDB shell version: 2.0.2
connecting to: test
> x=200
200
> x/4
50
> "Hello,World!".replace("World","Steven")
Hello,Steven!
> Math.sin(20)
0.9129452507276277
> db
test
> db
test
> use foobar
switched to db foobar
> db
foobar
> post = {"title": "My Blog Post",
... "connect" : "Here is my blog post.",
... "date" : new Date()}
{
"title" : "My Blog Post",
"connect" : "Here is my blog post.",
"date" : ISODate("2012-02-28T07:12:28.484Z")
}
> db.blog.insert(post)
> db.blog.findOne()
{
"_id" : ObjectId("4f4c7eb9afbc714c34cf32b0"),
"title" : "My Blog Post",
"connect" : "Here is my blog post.",
"date" : ISODate("2012-02-28T07:12:28.484Z")
}
> post.comment = []
[ ]
> db.blog.update({title : "My Blog Post"},post)
> db.blog.find()
{ "_id" : ObjectId("4f4c7eb9afbc714c34cf32b0"), "title" : "My Blog Post", "conne
ct" : "Here is my blog post.", "date" : ISODate("2012-02-28T07:12:28.484Z"), "co
mment" : [ ] }
> db.blog.remove({title : "My Blog Post"})
> db.blog.find()
> help
> db.foo.update
function (query, obj, upsert, multi) {
assert(query, "need a query");
assert(obj, "need an object");
var firstKey = null;
for (var k in obj) {
firstKey = k;
break;
}
if (firstKey != null && firstKey[0] == "$") {
this._validateObject(obj);
} else {
this._validateForStorage(obj);
}
this._mongo.update(this._fullName, query, obj, upsert ? true : false, multi
? true : false);
}
> db.getCollection("version");
foobar.version
> db.blog.insert({"title" : "Steven"})
> db.blog.find()
{ "_id" : ObjectId("4f4c8a8fafbc714c34cf32b2"), "title" : "Steven" }
> db.blog.findOne()
{ "_id" : ObjectId("4f4c8a8fafbc714c34cf32b2"), "title" : "Steven" }
> db.blog.remove()
> db.blog.findOne()
null
> post = {"cid" :001,
... "name" : "Steven",
... "date" : new Date()}
{
"cid" : 1,
"name" : "Steven",
"date" : ISODate("2012-02-28T08:11:05.078Z")
}
> db.user.insert(post);
> db.user.findOne()
{
"_id" : ObjectId("4f4c8c3dafbc714c34cf32b3"),
"cid" : 1,
"name" : "Steven",
"date" : ISODate("2012-02-28T08:11:05.078Z")
}
D:\\mongodb-win32-i386-2.0.2\\bin>mongo.exe
MongoDB shell version: 2.0.2
connecting to: test
> x=200
200
> x/4
50
> "Hello,World!".replace("World","Steven")
Hello,Steven!
> Math.sin(20)
0.9129452507276277
> db
test
> db
test
> use foobar
switched to db foobar
> db
foobar
> post = {"title": "My Blog Post",
... "connect" : "Here is my blog post.",
... "date" : new Date()}
{
"title" : "My Blog Post",
"connect" : "Here is my blog post.",
"date" : ISODate("2012-02-28T07:12:28.484Z")
}
> db.blog.insert(post)
> db.blog.findOne()
{
"_id" : ObjectId("4f4c7eb9afbc714c34cf32b0"),
"title" : "My Blog Post",
"connect" : "Here is my blog post.",
"date" : ISODate("2012-02-28T07:12:28.484Z")
}
> post.comment = []
[ ]
> db.blog.update({title : "My Blog Post"},post)
> db.blog.find()
{ "_id" : ObjectId("4f4c7eb9afbc714c34cf32b0"), "title" : "My Blog Post", "conne
ct" : "Here is my blog post.", "date" : ISODate("2012-02-28T07:12:28.484Z"), "co
mment" : [ ] }
> db.blog.remove({title : "My Blog Post"})
> db.blog.find()
> help
> db.foo.update
function (query, obj, upsert, multi) {
assert(query, "need a query");
assert(obj, "need an object");
var firstKey = null;
for (var k in obj) {
firstKey = k;
break;
}
if (firstKey != null && firstKey[0] == "$") {
this._validateObject(obj);
} else {
this._validateForStorage(obj);
}
this._mongo.update(this._fullName, query, obj, upsert ? true : false, multi
? true : false);
}
> db.getCollection("version");
foobar.version
> db.blog.insert({"title" : "Steven"})
> db.blog.find()
{ "_id" : ObjectId("4f4c8a8fafbc714c34cf32b2"), "title" : "Steven" }
> db.blog.findOne()
{ "_id" : ObjectId("4f4c8a8fafbc714c34cf32b2"), "title" : "Steven" }
> db.blog.remove()
> db.blog.findOne()
null
> post = {"cid" :001,
... "name" : "Steven",
... "date" : new Date()}
{
"cid" : 1,
"name" : "Steven",
"date" : ISODate("2012-02-28T08:11:05.078Z")
}
> db.user.insert(post);
> db.user.findOne()
{
"_id" : ObjectId("4f4c8c3dafbc714c34cf32b3"),
"cid" : 1,
"name" : "Steven",
"date" : ISODate("2012-02-28T08:11:05.078Z")
}
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




