MongoId
This is the last active development release of this package as Ocop 5 is now in a 6 to 12 month active maintenance phase. For more information please read our Ocop 5 and beyond post.
This field allows arbitrary Mongo ObjectId
fields to be added to your lists.
It supports the core Mongoose and Knex adapters:
- On Mongoose the
native Mongo
ObjectId
schema type is used. - On Knex a 24 character string field is
added to the schema. This resolves down to
varchar(24)
,character varying(24)
or similar, depending on the underlying DB platform. Values stored are forced to lowercase on read and write to avoid issues with case-sensitive string comparisons. See the casing section for details.
yarn add @ocopjs/fields-mongoid
Usage
const { Ocop } = require("@ocop/ocop");
const { MongoId } = require("@ocop/fields-mongoid");
const ocop = new Ocop(/* ... */);
ocop.createList("Product", {
fields: {
name: { type: Text },
oldId: { type: MongoId },
// ...
},
});