MongoDB
 sql >> Teknologi Basis Data >  >> NoSQL >> MongoDB

Luwak findById() dalam objek skema/subdokumen bersarang - agregasi

Demo - https://mongoplayground.net/p/t5VYdkrL_nC

db.collection.aggregate([
  {
    $match: { // filter the document so uniwnd and group have only 1 record to deal with
      $or: [
        { "types.exampleOne._id": "608a5b290e635ece6828141e" },
        { "types.exampleTwo._id": "608a5b290e635ece6828141e" }
      ]
    }
  },
  {
    $group: {
      _id: "$_id",
      docs: { $first: { "$concatArrays": [ "$types.exampleOne", "$types.exampleTwo" ] } } // join both array into 1 element
    }
  },
  { $unwind: "$docs" }, //  break into individual documents
  {
    $match: { // filter the records
     "docs._id": "608a5b290e635ece6828141e"
    }
  },
  { $replaceRoot: { "newRoot": "$docs" } } // set it to root
])



  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. Node.js + Mongoose / Mongo &bidang _id yang dipersingkat

  2. Java:Bagaimana cara memasukkan hashmap ke MongoDB?

  3. Permintaan MongoDB sederhana sangat lambat meskipun indeks disetel

  4. mongodb proyek agregasi objectId dengan concat

  5. MongoDB &CodeIgniter:Pilih di mana ada bidang