标签:mongodb 数据库 database nosql 数据
sudo service mongodb start
mongo
> use post #创建post数据库,并向其中插入文档
> db.post.insert([
{
title: 'MongoDB Overview',
description: 'MongoDB is no sql database',
by: 'shiyanlou',
url: 'http://www.shiyanlou.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 100
},
{
title: 'NoSQL Database',
description: "NoSQL database doesn't have tables",
by: 'shiyanlou',
url: 'http://www.shiyanlou.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 20,
comments: [
{
user:'user1',
message: 'My first comment',
dateCreated: new Date(2013,11,10,2,35),
like: 0
}
]
}
])
db.post.find()
db.post.find().pretty()
db.post.find({"by":"shiyanlou","title": "MongoDB Overview"}).pretty()
> db.post.find(
{
$or: [
{key1: value1}, {key2:value2}
]
}
).pretty()> db.post.find({
"likes": {$gt:10},
$or: [
{"by": "shiyanlou"},
{"title": "MongoDB Overview"}
]
}).pretty() #<span style="color: rgb(51, 51, 51); font-family: 'Microsoft Yahei'; font-size: 16px; line-height: 25.59375px;">{\$gt:10} 表示大于10,另外,\$lt 表示小于,\$lte 表示小于等于,\$gte 表示大于等于,\$ne 表示不等于。</span>标签:mongodb 数据库 database nosql 数据
原文地址:http://blog.csdn.net/djd1234567/article/details/46391317