mongodb(四)-文档
参考:
http://www.yiibai.com/mongodb/mongodb_insert_document.html
一、insert
语法:db.COLLECTION_NAME.insert(Document)
> db.joan3.insert({_id:ObjectId(1234567890),title:'JOAN'}) WriteResult({ "nInserted" : 1 })
如果集合在数据库中不存在,那么mongodb将自动创建此集合,然后把它插入文档。
_id
注意其中一个属性:_id。如果我们不指定这个id,mongodb会自动分配一个独特的ObjectId。_id是12个字节的十六进制数,12个字节划分如下:
_id: ObjectId(4 bytes timestamp, 3 bytes machine id, 2 bytes process id, 3 bytes incrementer)
批量插入:
db.joan3.insert({},{})
二、find
非结构化查询所有文件。
语法:db.COLLECTION_NAME.find()
pretty方法:格式化显示结果
语法:db.COLLECTION_NAME.find().pretty()
Equality | {<key>:<value>} | db.mycol.find({"by":"tutorials point"}).pretty() | where by = 'tutorials point' |
Less Than | {<key>:{$lt:<value>}} | db.mycol.find({"likes":{$lt:50}}).pretty() | where likes < 50 |
Less Than Equals | {<key>:{$lte:<value>}} | db.mycol.find({"likes":{$lte:50}}).pretty() | where likes <= 50 |
Greater Than | {<key>:{$gt:<value>}} | db.mycol.find({"likes":{$gt:50}}).pretty() | where likes > 50 |
Greater Than Equals | {<key>:{$gte:<value>}} | db.mycol.find({"likes":{$gte:50}}).pretty() | where likes >= 50 |
Not Equals | {<key>:{$ne:<value>}} | db.mycol.find({"likes":{$ne:50}}).pretty() | where likes != 50 |
相关推荐
lbyd0 2020-11-17
BigYellow 2020-11-16
sushuanglei 2020-11-12
我心似明月 2020-11-09
zhushenghan 2020-11-09
sunnnyduan 2020-10-16
不要皱眉 2020-10-14
xiaohai 2020-09-29
songxiugongwang 2020-09-22
萌亖 2020-09-17
LuckyLXG 2020-09-08
sdmzhu 2020-09-01
mkhhxxttxs 2020-09-16
xiaohai 2020-09-16
newcome 2020-09-09
jaylong 2020-08-19
大秦铁骑 2020-08-19
thatway 2020-08-19