mongodb 杂记

1. insertDocument :: caused by :: 11000 E11000 duplicate key error index: perf_test.test.$_id_  dup key: { : ObjectId('597edae0faa2ec5e6859e7a3') }
code is wrong, there have two line to insert the same document, so fail

2. 16555: 'exception: $multiply only supports numeric types, not String
in $multiply, you need use number insead of string

3. 16810: 'exception: bad query: BadValue unknown top level operator: $avg'
there no $avg field in document, you should remove $, let mongodb know it, to find it from stage output

4. Group by null
The _id field is mandatory; however, you can specify an _id value of null to calculate accumulated values for all the input documents as a whole.

5. group with system variable
$$ROOT --> current whole document

6. system variable & let variable
https://docs.mongodb.com/manual/reference/operator/aggregation/let/#exp._S_let
https://docs.mongodb.com/manual/reference/aggregation-variables/#agg-system-variables

7. type
New in version 3.4.
https://docs.mongodb.com/manual/reference/operator/aggregation/type/#exp._S_type

8. limit
The maximum BSON document size is 16 megabytes.
MongoDB supports no more than 100 levels of nesting for BSON documents.
A single collection can have no more than 64 indexes.
index key limit?

https://docs.mongodb.com/manual/reference/limits/#BSON-Document-Size

9. $group & $sort memory limit
The $group stage has a limit of 100 megabytes of RAM. By default, if the stage exceeds this limit, $group will produce an error. However, to allow for the handling of large datasets, set the allowDiskUse option to true to enable $group operations to write to temporary files.

11. $sort Operator and Performance
$sort operator can take advantage of an index when placed at the beginning of the pipeline or placed before the $project, $unwind, and $group aggregation operators. If $project, $unwind, or $group occur prior to the $sort operation, $sort cannot use any indexes.

12. run command from Java driver
eval command:
{
  eval: <function>,
  args: [ <arg1>, <arg2> ... ],
  nolock: <boolean>
}

map to java ==>
Document command = new Document();
command.put("eval", "function () { var result = db.test.findOne( { test_name : \"test_name0\" }); return Object.bsonsize(result); }");
command.put("args", "");
    
commnd list
https://docs.mongodb.com/manual/reference/command/

13. calculate median in mongodb
The simplest way to compute the median would be with these two statements (assuming the attribute on which we want to compute the median is called a and we want it over all documents in the collection, coll):

count = db.coll.count();
db.coll.find().sort( {"a":1} ).skip(count / 2 - 1).limit(1);

https://www.compose.com/articles/mongo-metrics-finding-a-happy-median/

14. how to define the primary key in self
_id field is reserved for primary key in mongodb, and that should be a unique value. If you don't set anything to _id it will automatically fill it with "MongoDB Id Object". But you can put any unique info into that field.

15. if you put two difference thing as primary key, then group by may not work well

16. index and compund index
index max limit is 64, compund index max limit is 31.
the 64 means the all index count should not exceed 64(normal and compund)

17. ??
The total size of an index entry, which can include structural overhead depending on the BSON type, must be less than 1024 bytes.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值