MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / listObjectContexts

Function listObjectContexts

storage/listObjectContexts.js:41–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39 const storage = new Storage();
40
41 async function listObjectContexts() {
42 // Define the filter for contexts.
43 const bucket = storage.bucket(bucketName);
44
45 /**
46 * List any object that has a context with the specified key and value.
47 * Syntax: contexts."<key>"="<value>"
48 */
49 const filterByValue = 'contexts."priority"="high"';
50 const [filesByValue] = await bucket.getFiles({
51 filter: filterByValue,
52 });
53
54 console.log(`\nFiles matching filter [${filterByValue}]:`);
55 filesByValue.forEach(file => console.log(` - ${file.name}`));
56
57 /**
58 * List any object that has a context with the specified key attached.
59 * Syntax: contexts."<key>":*
60 */
61 const filterByExistence = 'contexts."team-owner":*';
62 const [filesWithKey] = await bucket.getFiles({
63 filter: filterByExistence,
64 });
65
66 console.log(
67 `\nFiles with the "team-owner" context key [${filterByExistence}]:`
68 );
69 filesWithKey.forEach(file => console.log(` - ${file.name}`));
70
71 /**
72 * List any object that does not have a context with the specified key and value attached.
73 * Syntax: -contexts."<key>"="<value>"
74 */
75 const absenceOfValuePair = '-contexts."priority"="high"';
76 const [filesNoHighPriority] = await bucket.getFiles({
77 filter: absenceOfValuePair,
78 });
79
80 console.log(
81 `\nFiles matching absence of value pair [${absenceOfValuePair}]:`
82 );
83 filesNoHighPriority.forEach(file => console.log(` - ${file.name}`));
84
85 /**
86 * List any object that does not have a context with the specified key attached.
87 * Syntax: -contexts."<key>":*
88 */
89 const absenceOfKey = '-contexts."team-owner":*';
90 const [filesNoTeamOwner] = await bucket.getFiles({
91 filter: absenceOfKey,
92 });
93
94 console.log(
95 `\nFiles matching absence of key regardless of value [${absenceOfKey}]:`
96 );
97 filesNoTeamOwner.forEach(file => console.log(` - ${file.name}`));
98 }

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected