.net - RavenDB Migration: update property from string to array of strings -
i have collection of documents named actions. action in db looks this:
{ "name": "name1", "actiontype": "typea" }
i need migrate actions actiontype property contain array of strings:
{ "name": "name1", "actiontype": ["typea"] }
i don't want create converters in project mentioned here. should simple utility can run separately.
the idea load documents, made necessary changes , save them (like here). current code looks doesn't work correctly:
using system.collections; using system.collections.generic; using system.linq; using raven.client; using raven.client.document; using raven.client.linq; using raven.json.linq; namespace ravendbmigration { public class simplemigrator { private readonly idocumentstore _documentstore; public simplemigrator(idocumentstore documentstore) { _documentstore = documentstore; } public void run() { using (idocumentsession session = _documentstore.opensession()) { var fullravenidslist = new list<string> {"1", "2", "3"}; ravenjobject[] ravenjobjects = session.load<ravenjobject>(fullravenidslist); // problem here - ravenjobjects contains 3 null values instead of actions foreach (var ravenjobject in ravenjobjects) { var results = ravenjobject["actions"] ravenjarray; if (results != null) { foreach (var result in results) { if (result != null && result.containskey("actiontype")) { var actiontypes = new list<string>(); var actiontype = result.value<string>("actiontype"); if (actiontype != null) { actiontypes.add(actiontype); } result["actiontype"] = new ravenjarray(actiontypes); } } } } session.savechanges(); } } } }
i use ravendb.client of version 2.5.2700.
you can patch document collection "actions" either via raven studio or via code.
this.actiontype = [this.actiontype];
this result in document looking this:
"name": "name1", "actiontype": [ "typea" ]
hope helps!
Comments
Post a Comment