Hi Team,
Is there a way to retrieve the information on whether changeStreamPreAndPostImages is enabled/disabled for a collection?
I was able to enable it using runCommand as below. But not sure how to fetch the value that’s been set.
db.runCommand( {
collMod: "mycollection",
changeStreamPreAndPostImages: { enabled: true }
} )
Also is there a way to set this changeStreamPreAndPostImages on the database level instead for each collection?
Thanks in advance,
Sabareesh
Jason_Tran
(Jason Tran)
November 16, 2023, 10:47pm
2
Hi @Sabareesh_Babu ,
Will db.getCollectionInfos() work for you?
Please view the example below where I create a collection, run db.getCollectionInfos() to check the options on the collections in the database, enable the changeStreamPreAndPostImages option on the created collection and then finally run db.getCollectionInfos() again to check the options on the collection:
db> show collections
db> db.createCollection("collection")
{ ok: 1 }
db> db.getCollectionInfos()
[
{
name: 'collection',
type: 'collection',
options: {},
info: {
readOnly: false,
uuid: new UUID("85ec92c3-16da-41db-bd42-07654f449a46")
},
idIndex: { v: 2, key: { _id: 1 }, name: '_id_' }
}
]
/// Setting changeStreamPreAndPostImages option
db> db.runCommand({collMod:"collection",changeStreamPreAndPostImages: { enabled: true } })
{
ok: 1,
...
}
Output from db.getCollectionInfos() after setting the option:
db> db.getCollectionInfos()
[
{
name: 'collection',
type: 'collection',
options: { changeStreamPreAndPostImages: { enabled: true } }, /// <--- option enabled
info: {
readOnly: false,
uuid: new UUID("85ec92c3-16da-41db-bd42-07654f449a46")
},
idIndex: { v: 2, key: { _id: 1 }, name: '_id_' }
}
]
To my knowledge I haven’t seen if there is a way to do this at the database level.
Regards,
Jason
Jason_Tran:
db.getCollectionInfos()
Thanks Jason. Is there an equivalent C++ API for getCollectionInfos?
I was looking into mongoc_collection_t - libmongoc 2.1.0 but couldn’t find one.
Jason_Tran
(Jason Tran)
November 17, 2023, 2:24am
4
Not certain but can you try this one out: mongoc_database_find_collections_with_opts() - libmongoc 1.25.1
Otherwise I can check with the team
The db.getCollectionInfos() is a helper for mongosh but it’s output is similar to that of listCollections . i.e. db.runCommand({listCollections:1}) also shows the collection information including the options.
Hope this helps and look forward to hearing from you.
Regards,
Jason
Thanks for the quick response.Will check mongoc_database_find_collections_with_opts.
1 Like
Jason_Tran
(Jason Tran)
November 17, 2023, 5:42am
6
Cool - If it works, try and update this post so that it hopefully helps others using the same in future
system
(system)
Closed
November 22, 2023, 5:42am
7
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.