Comments (2)
Please modify the script below to demonstrate your issue
import { model, Schema, Types, connect, connection } from "mongoose";
interface ISavedAttribute {
attributeId: number,
attributeName: string,
productId: number,
displayName: string,
displayOn: [string]
}
const savedAllmoxyAttributes = new Schema(
{
_id: { type: Types.ObjectId, default: () => new Types.ObjectId() },
attributeId: { type: Number, required: true },
attributeName: { type: String, required: true },
productId: { type: Number, required: true },
displayName: { type: String, required: true },
displayOn: { type: [String], required: true },
},
{ collection: "allmoxy", timestamps: true }
);
const AllmoxySavedAttribute = model<ISavedAttribute>(
"allmoxy-saved-attributes",
savedAllmoxyAttributes
);
async function run() {
await connect('mongodb://localhost:27017');
await connection.dropDatabase();
const existingEntry = await AllmoxySavedAttribute.findOne();
if (existingEntry)
return this.returnError(
"An object with that attribute ID already exists!"
);
const createdEntry = await AllmoxySavedAttribute.create({
attributeId: 1,
attributeName: 'Test',
productId: 1,
displayName: 'test testerson',
displayOn: ['Test']
});
console.log(createdEntry);
console.log(createdEntry._id)
}
run();
from mongoose.
🤦 that's my bad. I was sending _id from the frontend, and in some cases it was null, so that's what the document returned. Thank-you!
from mongoose.
Related Issues (20)
- Virtuals not serialized after v8.5 HOT 3
- Cursor.next can return null, but TypeScript says it can't
- `this` context in nested schema `required` functions changed since mongoose 7.0.2+ HOT 2
- mongoose.connection.db can be undefined, but TypeScript says it can't
- Connection Error and not getting any data - DEP0170 HOT 1
- Intersection type error in embedded schema when iterating through an embedded array HOT 3
- Populate + lean + multiple populated documents leads to "Cannot read properties of undefined (reading '_id')" in version 8.5.2 HOT 1
- After replica election, mongoose can't connect to mongo db and throw timeout error each 30s HOT 2
- Issue deleted
- Model.bulkWrite options strict weird behavior HOT 1
- Question about .findOne() HOT 1
- can not specify zstd compression level HOT 4
- Mongoose.prototype.connect() : Discrepancy between changelog and example in document. HOT 1
- How to type added static methods and query helpers
- populated sub-documents have same references HOT 1
- Transaction aborts when used with `ordered: false`
- Model.applyVirtuals(): apply schema virtuals to a POJO, similar to Model.applyDefaults() HOT 4
- Discriminator Method Modifies Schema Argument in Mongoose HOT 2
- Mongoose creates duplicate collections when name includes uppercase characters HOT 1
- There is a bug thats i dont save HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoose.