2016-03-20 14 views

cevap

1

Mongoid sınıfları çekirdek sürücüsünden Collection nesneye erişim sağlayan bir .collection erişimci sahiptir.

Ama genellikle standart nesnelerin daha tutarlı bulk_write() yöntem ve diziler kullanmak Modern sürücüleri tercih edilir:

ops = []; 

ops.push({ "insert_one" => { "_id" => 1 } }) 
ops.push({ "insert_one" => { "_id" => 1 } }) 
ops.push({ "insert_one" => { "_id" => 3 } }) 
ops.push({ "insert_one" => { "_id" => 3 } }) 

Class.collection.bulk_write(ops,{ "ordered" => false }) 

Hatta insert_many() sadece eklemeleri yapıyor ve yazma işlemlerinin türlerini karıştırma değilse:

Class.collection.insert_many([ 
    { "_id" => 1 }, 
    { "_id" => 1 }, 
    { "_id" => 3 }, 
    { "_id" => 3 } 
],{ "ordered" => false })