3

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.

prasadv
  • 73
  • 5
  • 1
    How do you create the document? can you provide some code ? Try to create with document name all lower-case ! – Danielle Apr 14 '19 at 07:42
  • 1
    @Danielle Below is a snippet of how I store the document. I am using the apollo node client. ```const sched: IScheduling = { appointment: { id: 'appointments/1-A', client: { id: 'clients/1-A', name: 'Entity', }, }, status: 'Pending', tier: 1, sendOn: new Date() }; await session.store(sched); await session.saveChanges(); ``` – prasadv Apr 14 '19 at 09:29

2 Answers2

3

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.

prasadv
  • 73
  • 5
2
  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
Danielle
  • 3,324
  • 2
  • 18
  • 31