duancuan6466 2011-08-18 06:04
浏览 109
已采纳

在mongoDB中创建集合可能会引起一些冲突?

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"?

  • 写回答

1条回答 默认 最新

  • douyan1453 2011-08-18 12:43
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。