mongodb文档中的过期元素

mongodb文档中的过期元素,mongodb,mongodb-php,Mongodb,Mongodb Php,注意:第一次使用MongoDB 技术:php mongodb 情景: 这些数据被认为包含提供的程序。文档看起来像: { LocationName: 'name of the location', LocationAddress: 'Main street., Popular City, PC', LocationManager: 'Mr. Manager', LocationPhone: '555 555 1212', Programs :

注意:第一次使用MongoDB

技术:php mongodb 情景:

这些数据被认为包含提供的程序。文档看起来像:

{
    LocationName: 'name of the location',
    LocationAddress: 'Main street., Popular City, PC',
    LocationManager: 'Mr. Manager',
    LocationPhone: '555 555 1212',
    Programs :
             [
                 {
                 ProgramName : 'Excellence Prgram',
                 ProgramStartDate : '12-05-2012',
                 ProgramEndDate : '3-15-2013'
                 },
                 {
                 ProgramName : 'Excellence Prgram for me',
                 ProgramStartDate : '1-05-2012',
                 ProgramEndDate : '2-15-2013'
                 },
                 {
                 ProgramName : 'Excellence Prgram for three',
                 ProgramStartDate : '1-05-2012',
                 ProgramEndDate : '4-15-2013'
                 }
             ]
}
问题:

  • 要按开始日期和结束日期查询,对集合的查询是什么
  • 这些程序在结束日期前过期,新程序会频繁添加到每个文档中。我认为,在文档中保留过期的程序在某种程度上会变得效率低下。如何存档过期的程序

  • 事先谢谢你。

    请原谅,我讨厌给出这种回答。我将彻底改变您存储文档的方式:

    我将使文档如下所示:

     {
         _id : 1823098123908831809
         ProgramName : 'Excellence Prgram',
         ProgramStartDate : '12-05-2012',
         ProgramEndDate : '3-15-2013'
         Location : {
             LocationName: 'name of the location',
             LocationAddress: 'Main street., Popular City, PC',
             LocationManager: 'Mr. Manager',
             LocationPhone: '555 555 1212',
     }
    
    现在的问题是,您可以查询具有活动程序的位置,但仅提取符合业务规则的程序将非常棘手

    使用此reorg,您可以为集合中日期符合业务规则的所有文档编写一个简单的查询

    位置更改细节确实会变得更复杂,但这实际上是一个小用例。您将经常查询活动程序。地点很少更换经理


    这也将允许您维护历史记录。如果您只更新项目相关运行的位置信息,您将有一个记录,即2013年5月卓越运行项目发生在Mains street的旧位置,由经理先生主持(尽管现在在Front street举行,由经理夫人主持)。

    显然,这是一个很难解决的问题。