开发者

collection creation in mongoDB may cause some conflicts?

Assume $db is a made mongoDB connection with php.

There is no collection exists yet.

I inserted one data

$db->board_name->board->article->insert(array("title"=>"example"));

this is equivalent to

db.board_name.board.article.insert({开发者_开发技巧"title":"example"})

the problem is it inserts not the

db.board_name.board

structure but

just simply inserts "db.board_name.board.article" <--- these three as a string.

Does it just demonstrates like a combined string for now

because there is no other elements after "board_name"?

What if I add more things right after "board_name" like

db.board_name.rank.insert({"something":"thing"});

Does mongoDB smartly recognize "rank" collection as part of "board_name" in that case?

or simply creates other collection with "db.board_name.rank"?


I'm not sure if I understand correctly, but what I think you're asking is, "why is there no collection named board_name.name"? That's because you haven't created one yet.

Each collection in MongoDB simply has a name. The fact that human beings (and drivers) use .s to separate the names into logical namespaces is a convenience to make it easier to use, and to let you logically group related collections, but from MongoDB's perspective, the name is simply a string.

Once you've created board_name.name.article, if you issue a subsequent insert or save operation to another collection, say, board_name.rank, then that collection will be created for you at that time. There will be no conflicts, your insert, update, or save operation will either identify a collection which already exists, and operate on that, or create a new collection and operate on that.

For more on how collections work, see the MongoDB docs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜