Mongodb基础操作实践- -Mongodb Shell端

一、连接

1.mongo mongodb://localhost:27000

2.

show databases(dbs)

use test

3.

db

show collections

二、插入

1.db.proccessedfile.insertone({fileName:"20170403/3.gz", processedDate:new ISODate(), dataNumber:10000, x:10})

2.db.mongodb.insertMany([    { item: "journal", qty: 25, tags: ["blank", "red"], size: { h: 14, w: 21, uom: "cm" } },    { item: "mat", qty: 85, tags: ["gray"], size: { h: 27.9, w: 35.5, uom: "cm" } },    { item: "mousepad", qty: 25, tags:["gel", "blue"], size: { h: 19, w: 22.85, uom: "cm" } } ])

三、查询

1.

db.proccessedfile.find()

db.proccessedfile.find().pretty()//pretty格式化,document或bson.document,类json标准格式输出,基于查询均可追加上

2.db.mongodb.find( { item: "mousepad" } )

3.db.mongodb.find( { qty: {$in: [25, 29]} } ).pretty()//=,后接数组数据的集合,类似or操作,$or后接数组集合的集合

4.

db.mongodb.find( {qty: {$lte: 85}} ).pretty()//>=

db.mongodb.find( {qty: {$lte: 85, $gte: 25 }} ).pretty()//>=, <=

db.mongodb.find( {item: "mousepad", qty: {$lte: 85, $gte: 25 }} ).pretty()//and操作

posted @ 2017-07-09 10:34  tangyongathuse  阅读(205)  评论(0编辑  收藏  举报