scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
556 stars 80 forks source link

Search by reference Document. #83

Open devdebonair opened 8 years ago

devdebonair commented 8 years ago
class Ticket extends Document {
    constructor() {
        super();

        this.user = User;
        this.event = Event;
    }

    static collectionName() {
        return "tickets";
    }
}

Ticket.find({event: "random ObjectID"})

No matter what this always comes back as an empty array and I am sure the document is in the database. When I pass the find function an ObjectID(), I get an error stating that the argument must be a string. I am able to find it in the console through this command.

db.tickets.find({ "_id": ObjectId("random ObjectID") })

Any ideas why this may be happening?

ghost commented 7 years ago

I have the same problem here. Is this implemented or is not supported?

ghost commented 7 years ago

@devdebonair I found something that may help. Passing an new ObjectID('random ObjectID') to find does work, but using the latest mongodb package is incompatible, switching to the same version camo is using (2.0.42) works.

import { ObjectID } from 'mongodb';

DB.then(() => {
  Character
    .find({
      owner: new ObjectID('some random ID')
    })
    .then(res => res.map(u => u.toJSON()))
});