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.

2
  • 1
    How do you create the document? can you provide some code ? Try to create with document name all lower-case ! Commented Apr 14, 2019 at 7: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<Scheduling>(sched); await session.saveChanges(); Commented Apr 14, 2019 at 9:29

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.