Skip to content

Commit

Permalink
set feature flags headers on collection httpClient as well
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Sep 27, 2024
1 parent d8cd0e2 commit f7d5778
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/driver/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export class Collection extends MongooseCollection {

//getter for collection
get collection() {
return this.conn.db.collection(this.name);
const collection = this.conn.db.collection(this.name);
Object.assign(collection._httpClient.baseHeaders, this.conn.featureFlags);
return collection;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/driver/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class Connection extends MongooseConnection {
const featureFlags: Record<string, 'true'>| null = Array.isArray(options && options.featureFlags)
? options.featureFlags.reduce((obj: Record<string, 'true'>, key: string) => Object.assign(obj, { [key]: 'true' }), {})
: null;
this.featureFlags = featureFlags;

const client = options?.isAstra
? new DataAPIClient(applicationToken)
Expand Down
5 changes: 4 additions & 1 deletion tests/driver/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ describe('Mongoose Model API level tests', async () => {
assert.ok(res.status.collections.includes('carts'));
});
it('API ops tests collection.runCommand()', async () => {
console.log('XT', mongooseInstance!.connection.db.collection('carts'));
const res = await mongooseInstance!.connection.db.collection('carts')._httpClient.executeCommand({ find: {} });
assert.ok(Array.isArray(res.data.documents));
});
Expand Down Expand Up @@ -752,6 +751,10 @@ describe('Mongoose Model API level tests', async () => {
}
});
assert.ok(res.status.ok);

const Bot = mongoose.model('Bot', new mongoose.Schema({ name: String }), 'bots');
await Bot.findOne();

await mongoose.disconnect();
});
});
Expand Down

0 comments on commit f7d5778

Please sign in to comment.