You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
system: Linux Debian (from node:20.11.1-slim Docker image)
package: mongo-memory-server
What is the Problem?
When using mongodb-memory-server with a timeseries collection in test environment, attempting to insert documents results in MongoServerError: Namespace X is a view, not a collection. The same code works correctly with a local MongoDB instance.
This appears to be a discrepancy in how mongodb-memory-server handles timeseries collections compared to a standard MongoDB installation.
Code Example
// Model definitionconstpostSchema: Schema=newmongoose.Schema({date: {type: Date,required: true},content: {type: String,required: true}},{toJSON: {virtuals: true},toObject: {virtuals: true},timeseries: {timeField: "date",granularity: "hours"},autoCreate: true,timestamps: true});exportconstPost=mongoose.model<PostDocument>("Post",postSchema);// Test setupconst{ MongoMemoryReplSet }=require("mongodb-memory-server");constMONGO_VERSION="8.0.3";module.exports=async()=>{constreplicaSet=awaitMongoMemoryReplSet.create({instanceOpts: [{port: parseInt(process.env.DATABASE_IN_MEMORY_PORT)}],binary: {version: MONGO_VERSION},replSet: {count: 1,storageEngine: "wiredTiger"}});};// Test that failsdescribe("createAllPosts",()=>{beforeAll(async()=>{awaitbuildPost({content: "test content",});});it("should work with timeseries collection",async()=>{constposts=awaitPost.find();expect(posts.length).toBe(1);});});// helpersasyncfunctionbuildPost(overrides: Partial<PostDTOInterface>={}): Promise<PostDocument>{constdata: PostDTOInterface={date: newDate(Date.now()),content: faker.lorem.sentence(),
...overrides};returnnewPost(data).save();}
Error output
MongoServerError: Namespace PostCronService.posts is a view, not a collection
at InsertOneOperation.execute (node_modules/mongodb/src/operations/insert.ts:82:13)
at tryOperation (node_modules/mongodb/src/operations/execute_operation.ts:271:14)
at executeOperation (node_modules/mongodb/src/operations/execute_operation.ts:109:12)
at Collection.insertOne (node_modules/mongodb/src/collection.ts:277:12)
Do you know why it happens?
The issue seems specific to mongodb-memory-server as:
The exact same code works correctly with a local MongoDB instance
pavlos163
changed the title
Error when inserting into TimeSeries collections (MongoDB v8)
Error when inserting into time series collections (MongoDB v8)
Dec 10, 2024
pavlos163
changed the title
Error when inserting into time series collections (MongoDB v8)
Error when inserting into time series collections
Dec 10, 2024
pavlos163
changed the title
Error when inserting into time series collections
Fix error when inserting into time series collections
Dec 10, 2024
When using mongodb-memory-server with a timeseries collection in test environment, attempting to insert documents results in MongoServerError: Namespace X is a view, not a collection
That sounds like a weird error.
This appears to be a discrepancy in how mongodb-memory-server handles timeseries collections compared to a standard MongoDB installation.
mongodb-memory-server is basically a local installation, as MMS literally only handles download & running mongod binaries, so there shouldnt be a discrepancy with the same options.
In what part of the provided code does the error occur?
What version were you using when testing a "local installation"? (was that also a repl-set?)
Versions
package: mongo-memory-server
What is the Problem?
When using mongodb-memory-server with a timeseries collection in test environment, attempting to insert documents results in
MongoServerError: Namespace X is a view, not a collection
. The same code works correctly with a local MongoDB instance.This appears to be a discrepancy in how mongodb-memory-server handles timeseries collections compared to a standard MongoDB installation.
Code Example
Error output
Do you know why it happens?
The issue seems specific to mongodb-memory-server as:
The text was updated successfully, but these errors were encountered: