Session.Query + BulkInsert losing metadata

22 views
Skip to first unread message

Bruno

unread,
Nov 28, 2016, 5:18:21 PM11/28/16
to RavenDB - 2nd generation document database
Hello group,
I am doing a session.query/bulk insert to update records on my db and the operation runs ok except that I'm losing all my metadata after the records are updated.

The code is simple and looks like:

     // loads a list of recs...
     var docs = sess.Query<T>()
                            .Take(batchSize)
                            .Skip(count)
                            .ToList();

     // do stuf....

     // bulk update
using (var bulkInsert = store.BulkInsert(options: new BulkInsertOptions {
OverwriteExisting = true, 
SkipOverwriteIfUnchanged = true
}))
{
docs.ForEach(d => bulkInsert.Store(d));
}


Notes: 
  • I cannot use the patch functionality b/c I need to run complex back-end code on each record;
  • Client/Server in use is 3.0.30037

Is this the default behavior?

What do I need to do in order to be able to preserve my metadata after a bulk update since the GetMetadataFor can only be used per document?


Thanks.

Oren Eini (Ayende Rahien)

unread,
Nov 29, 2016, 2:16:18 AM11/29/16
to ravendb
Yes, you are overwriting the data, it you want to preserve the metadata, you need:

docs.ForEach(d => bulkInsert.Store(d, sess.Advanced.GetMetadataFor(d), d.Id));

Gmail code, the order of the params may be different.


Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bruno

unread,
Nov 29, 2016, 11:34:21 AM11/29/16
to RavenDB - 2nd generation document database
Thanks for the reply, Oren!

And for the record, we need to use the method RavenJObject.FromObject(d); to convert from an entity to RavenJObject.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages