MongoDB小技巧之如何使用带下划线的集合名查询

> show collections;
_test
_test_serial_number
_test_message_send
inventory
>


> db._test_message_send.find()
2017-09-29T01:52:37.612+0000 E QUERY    [thread1] TypeError: db._wechat_message_send is undefined :
@(shell):1:1


> db._test_message_send.count()
2017-09-29T01:53:25.302+0000 E QUERY    [thread1] TypeError: db._wechat_message_send is undefined :
@(shell):1:1

带下划线的集合名字查询的时候应使用getCollection,例如:

> db.getCollection('_test_message_send').count()
2562

> db.getCollection('_test_message_send').findOne()
{
        "_id" : "93e4cc65502344f584bfb385f94dde35",
        "_class" : "com.base.entities.WechatMessageSend",
        "type" : 4,
        "status" : 3,
        "memberId" : "863eee3694fc45",
        "openId" : "oB3wuwViNwa2G2NpOCdjMSvFJCcY",
        "templateId" : "2KKEiTYulLq4RxRudlNuX",
        "messageId" : "7a33b0f20e2e43c",
        "createTime" : ISODate("2016-07-19T00:23:37.346Z")
}

重命名集合名字:
> db.getCollection('_test').renameCollection("_test_bak20171011");
{ "ok" : 1 }



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15498/viewspace-2145584/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15498/viewspace-2145584/

你可能感兴趣的:(数据库,java)