prasadv
prasadv

Reputation: 73

While creating new document in ravendb, collection name is missing in metadata, and the document is marked under @empty collection

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

Answers (2)

Danielle
Danielle

Reputation: 3839

  1. If you are using Object Literals for the entities to be stored, then you need to set 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

  1. If you are using classes for entities to be stored, then an instance of the class must be passed to store()
    See: https://github.com/ravendb/ravendb-nodejs-client#using-classes-for-entities

Upvotes: 2

prasadv
prasadv

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

Related Questions