File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Registers the ab_testing feature flag without enabling it for anyone.
2+ //
3+ // Run against prod from a machine with the Mongo URI:
4+ // mongosh "$MONGODB_URI/url-shortener" scripts/seed_ab_testing_flag.js
5+ //
6+ // Idempotent: only inserts when no doc exists, so a flag a human has
7+ // already edited (allowlist, rollout) is never rewritten. Add accounts
8+ // afterwards with:
9+ // db.feature_flags.updateOne({name: "ab_testing"},
10+ // {$addToSet: {allowlist_emails: "someone@example.com" }})
11+ // and unregister with:
12+ // db.feature_flags.deleteOne({name: "ab_testing"})
13+ // The app picks changes up within the flag cache TTL (about 30s).
14+
15+ const now = new Date ( ) ;
16+ const result = db . feature_flags . updateOne (
17+ { name : "ab_testing" } ,
18+ {
19+ $setOnInsert : {
20+ name : "ab_testing" ,
21+ enabled : true ,
22+ rollout_type : "allowlist" ,
23+ allowlist_user_ids : [ ] ,
24+ allowlist_emails : [ ] ,
25+ percentage : 0 ,
26+ enabled_digits : [ ] ,
27+ tier : null ,
28+ description :
29+ "A/B split destinations (ab_variants). Allowlist until paid plans gate it by tier." ,
30+ created_at : now ,
31+ updated_at : now ,
32+ } ,
33+ } ,
34+ { upsert : true } ,
35+ ) ;
36+
37+ const doc = db . feature_flags . findOne ( { name : "ab_testing" } ) ;
38+ print ( result . upsertedCount ? "inserted ab_testing flag" : "ab_testing flag already registered, untouched" ) ;
39+ printjson ( {
40+ enabled : doc . enabled ,
41+ rollout_type : doc . rollout_type ,
42+ allowlist_emails : doc . allowlist_emails ,
43+ created_at : doc . created_at ,
44+ } ) ;
You can’t perform that action at this time.
0 commit comments