Reputation: 73
I am trying to create a new collection in ravendb using the apollo node client. Although the document is created and stored in ravendb, the "collection" value from metadata is missing. And as a result the document is stored under @empty collection. Wondering what is it that I am missing.
Upvotes: 3
Views: 658
Reputation: 3839
findCollectionNameForObjectLiteral()
on the DocumentStore
, before calling initialize()
const store = new DocumentStore(urls, database);
store.conventions.findCollectionNameForObjectLiteral = entity => entity["collection"];
// ...
store.initialize();
This must be done before the initialize() call on DocumentStore instance.
Otherwise, entities are created in the @empty collection.
See https://github.com/ravendb/ravendb-nodejs-client#using-object-literals-for-entities
store()
Upvotes: 2
Reputation: 73
I have found the solution. The issue was caused because I was trying to pass an on the fly Json object of an interface type, while it is required to pass an object of the class, implementing the interface. RavenDB uses the object's class name to set the id and to organize the documents under collections.
Upvotes: 3