赞
踩
null 用于表示空值或者不存在的字段
{“x”:null}
布尔类型有两个值 true 和 false
{“x”: true}
shell 默认使用64 位浮点型数值。因此,以下数值在shell中是很正常的
{“x”: 3.14} {“x”: 3}
对于数值型,可使用NumberInt (表示4字节带符号整数)
或NumberLong类(表示8字符符号整数)
分别举例如下
{“x”: NumberInt(“3”)} {“x”: NumberLong(“3”)}
UTF-8 字符串都可以表示为字符串类型的数据
{“x”: “foobar”}
日期被存储为自新纪元以来的毫秒数,不存储时区:
关于日期时间是按照 javascript 的风格来的
{“x”:new Date()}
查询时,使用正则表达式作为限定条件,语法也与JavaScript的正则表达式语法相同:
{“x”: /foobar/}
数据列表或数据集可以表示为数组
{“x”:[“a”,“b”,“c”]}
文档可嵌套其他文档,被嵌套的文档作为父文档的值:
{“x”:{“foo”:“bar”}}
对象id是一个12字节的Id,是文档的唯一标识。
1234567891011
时间戳+机器码+PID+计数器
{“x”:ObjectId()}
二进制数据和代码
help
db.help() 数据库级别的帮助
db.foo.help() 查看集合级别的帮助
db.foo.find().help() - show DBCursor help db.foo.bulkWrite( operations, <optional params> ) - bulk execute write operations, optional parameters are: w, wtimeout, j db.foo.count( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS db.foo.countDocuments( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS db.foo.estimatedDocumentCount( <optional params> ) - estimate the document count using collection metadata, optional parameters are: maxTimeMS db.foo.convertToCapped(maxBytes) - calls {convertToCapped:'foo', size:maxBytes}} command db.foo.createIndex(keypattern[,options]) db.foo.createIndexes([keypatterns], <options>) db.foo.dataSize() db.foo.deleteOne( filter, <optional params> ) - delete first matching document, optional parameters are: w, wtimeout, j db.foo.deleteMany( filter, <optional params> ) - delete all matching documents, optional parameters are: w, wtimeout, j db.foo.distinct( key, query, <optional params> ) - e.g. db.foo.distinct( 'x' ), optional parameters are: maxTimeMS db.foo.drop() drop the collection db.foo.dropIndex(index) - e.g. db.foo.dropIndex( "indexName" ) or db.foo.dropIndex( { "indexKey" : 1 } ) db.foo.hideIndex(index) - e.g. db.foo.hideIndex( "indexName" ) or db.foo.hideIndex( { "indexKey" : 1 } ) db.foo.unhideIndex(index) - e.g. db.foo.unhideIndex( "indexName" ) or db.foo.unhideIndex( { "indexKey" : 1 } ) db.foo.dropIndexes() db.foo.explain().help() - show explain help db.foo.reIndex() db.foo.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return. e.g. db.foo.find( {x:77} , {name:1, x:1} ) db.foo.find(...).count() db.foo.find(...).limit(n) db.foo.find(...).skip(n) db.foo.find(...).sort(...) db.foo.findOne([query], [fields], [options], [readConcern]) db.foo.findOneAndDelete( filter, <optional params> ) - delete first matching document, optional parameters are: projection, sort, maxTimeMS db.foo.findOneAndReplace( filter, replacement, <optional params> ) - replace first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument db.foo.findOneAndUpdate( filter, <update object or pipeline>, <optional params> ) - update first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument db.foo.getDB() get DB object associated with collection db.foo.getPlanCache() get query plan cache associated with collection db.foo.getIndexes() db.foo.insert(obj) db.foo.insertOne( obj, <optional params> ) - insert a document, optional parameters are: w, wtimeout, j db.foo.insertMany( [objects], <optional params> ) - insert multiple documents, optional parameters are: w, wtimeout, j db.foo.mapReduce( mapFunction , reduceFunction , <optional params> ) db.foo.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursor db.foo.remove(query) db.foo.replaceOne( filter, replacement, <optional params> ) - replace the first matching document, optional parameters are: upsert, w, wtimeout, j db.foo.renameCollection( newName , <dropTarget> ) renames the collection. db.foo.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name db.foo.save(obj) db.foo.stats({scale: N, indexDetails: true/false, indexDetailsKey: <index key>, indexDetailsName: <index name>}) db.foo.storageSize() - includes free space allocated to this collection db.foo.totalIndexSize() - size in bytes of all the indexes db.foo.totalSize() - storage allocated for all data and indexes db.foo.update( query, <update object or pipeline>[, upsert_bool, multi_bool] ) - instead of two flags, you can pass an object with fields: upsert, multi, hint, let db.foo.updateOne( filter, <update object or pipeline>, <optional params> ) - update the first matching document, optional parameters are: upsert, w, wtimeout, j, hint, let db.foo.updateMany( filter, <update object or pipeline>, <optional params> ) - update all matching documents, optional parameters are: upsert, w, wtimeout, j, hint, let db.foo.validate( <full> ) - SLOW db.foo.getShardVersion() - only for use with sharding db.foo.getShardDistribution() - prints statistics about data distribution in the cluster db.foo.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function db.foo.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if set db.foo.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collection db.foo.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection db.foo.latencyStats() - display operation latency histograms for this collection
mongodb.exe 后执行
for(var i = 0; i < 1000000; i ++) {
db.foo.insert({"name":"zhangsan" + i, "age" : i});
}
for(i=0;i<1000000;i++){
db.users.insert(
{
"i":i,"username":"user"+i,
"age":Math.floor(Math.random()*120),
"created":new Date()
}
)
};
db.getCollection("").mapReduce(function () {
emit(this.key, this.value);
}, function (key, values) {
return values[0];
}, {
out: {
inline: 1
},
verbose: true
});
net start Mongodb
net stop Mongodb
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。