-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Add support for MongoDB query comment #8928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mtrezza
merged 10 commits into
parse-community:alpha
from
Meglali20:add-comment-to-query-
Mar 3, 2024
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0fd3101
Initial commit to add comment to a query
Meglali20 66c778d
Merge branch 'alpha' into add-comment-to-query-
mtrezza b7d3e55
added more tests
Meglali20 d95e64e
fixed test for different mongoDb versions
Meglali20 f643ef3
Merge branch 'alpha' into add-comment-to-query-
mtrezza ffcd8d0
Fix failing lint check
Meglali20 9b2f03b
Merge branch 'add-comment-to-query-' of https://github.com/Meglali20/…
Meglali20 f4d2aaf
Merge branch 'alpha' into add-comment-to-query-
mtrezza 6c1cc3b
Merge branch 'alpha' into add-comment-to-query-
mtrezza 8595969
Merge branch 'alpha' into add-comment-to-query-
mtrezza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
'use strict'; | ||
|
||
const Config = require('../lib/Config'); | ||
const TestUtils = require('../lib/TestUtils'); | ||
const { MongoClient } = require('mongodb'); | ||
const databaseURI = 'mongodb://localhost:27017/'; | ||
const request = require('../lib/request'); | ||
|
||
let config, client, database; | ||
|
||
const masterKeyHeaders = { | ||
'X-Parse-Application-Id': 'test', | ||
'X-Parse-Rest-API-Key': 'rest', | ||
'X-Parse-Master-Key': 'test', | ||
'Content-Type': 'application/json', | ||
}; | ||
|
||
const masterKeyOptions = { | ||
headers: masterKeyHeaders, | ||
json: true, | ||
}; | ||
|
||
describe_only_db('mongo')('Parse.Query with comment testing', () => { | ||
beforeEach(async () => { | ||
config = Config.get('test'); | ||
client = await MongoClient.connect(databaseURI, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}); | ||
database = client.db('parseServerMongoAdapterTestDatabase'); | ||
const level = 2; | ||
const profiling = await database.command({ profile: level }); | ||
console.log(`profiling ${JSON.stringify(profiling)}`); | ||
}); | ||
|
||
afterEach(async () => { | ||
await client.close(); | ||
await TestUtils.destroyAllDataPermanently(false); | ||
}); | ||
|
||
it('send comment with query through REST', async () => { | ||
const comment = 'Hello Parse'; | ||
const object = new TestObject(); | ||
object.set('name', 'object'); | ||
await object.save(); | ||
const options = Object.assign({}, masterKeyOptions, { | ||
url: Parse.serverURL + '/classes/TestObject', | ||
qs: { | ||
explain: true, | ||
comment: comment, | ||
}, | ||
}); | ||
await request(options); | ||
const result = await database.collection('system.profile').findOne({}, { sort: { ts: -1 } }); | ||
expect(result.command.explain.comment).toBe(comment); | ||
}); | ||
|
||
it('send comment with query', async () => { | ||
const comment = 'Hello Parse'; | ||
const object = new TestObject(); | ||
object.set('name', 'object'); | ||
await object.save(); | ||
const collection = await config.database.adapter._adaptiveCollection('TestObject'); | ||
await collection._rawFind({ name: 'object' }, { comment: comment }); | ||
const result = await database.collection('system.profile').findOne({}, { sort: { ts: -1 } }); | ||
expect(result.command.comment).toBe(comment); | ||
}); | ||
|
||
it('send a comment with a count query', async () => { | ||
const comment = 'Hello Parse'; | ||
const object = new TestObject(); | ||
object.set('name', 'object'); | ||
await object.save(); | ||
|
||
const object2 = new TestObject(); | ||
object2.set('name', 'object'); | ||
await object2.save(); | ||
|
||
const collection = await config.database.adapter._adaptiveCollection('TestObject'); | ||
const countResult = await collection.count({ name: 'object' }, { comment: comment }); | ||
expect(countResult).toEqual(2); | ||
const result = await database.collection('system.profile').findOne({}, { sort: { ts: -1 } }); | ||
expect(result.command.comment).toBe(comment); | ||
}); | ||
|
||
it('attach a comment to an aggregation', async () => { | ||
const comment = 'Hello Parse'; | ||
const object = new TestObject(); | ||
object.set('name', 'object'); | ||
await object.save(); | ||
const collection = await config.database.adapter._adaptiveCollection('TestObject'); | ||
await collection.aggregate([{ $group: { _id: '$name' } }], { | ||
explain: true, | ||
comment: comment, | ||
}); | ||
const result = await database.collection('system.profile').findOne({}, { sort: { ts: -1 } }); | ||
expect(result.command.explain.comment).toBe(comment); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.