 in C:\Users\A\Downloads and how many elements there are in C:\Users\A\Documents. How can I do it?

A:

i want to see how many documents I have in a collection with the same
  base path:

Assuming you are supplying the base path to find the number of documents with that base path - the following regex query will count all the documents with the path field value staring with "C:\Users\A\Downloads\".
db.paths.find( { path: /^C:\\Users\\A\\Downloads\\/ } ).count()

Code Using MongoDB Java Driver:
Pattern p = Pattern.compile("^C:\\\\Users\\\\A\\\\Documents\\\\");
Bson queryFilter = regex("path", p);
long count = collection.countDocuments(filter);

The following is the data I am using; there are 4 documents. When I run the code I get a count of 2 (which is correct and expected as there are two paths which match the pattern "^C:\\Users\\A\\Documents\\").

Using the same data as shown in the Compass screenshot, the following aggregation
db.paths.aggregate( [
  { 
      $group : { 
          _id :  "Counts", 
          Documents: { 
              $sum: {
                  $cond: [ { $regexMatch: { input: "$path", regex: /^C:\\Users\\A\\Documents\\/ } }, 1, 0 ]
              } 
          },
          Downloads: { 
              $sum: {
                  $cond: [ { $regexMatch: { input: "$path", regex: /^C:\\Users\\A\\Downloads\\/ } }, 1, 0 ]
              } 
          }
      }
  },
] )

prints: 
{ "_id" : "Counts", "Documents" : 2, "Downloads" : 1 }

The Java code for the above aggregation:
Pattern docPattern = Pattern.compile("^C:\\\\Users\\\\A\\\\Documents\\\\");
Pattern downloadPattern = Pattern.compile("^C:\\\\Users\\\\A\\\\Downloads\\\\");

List<Bson> pipeline = 
    Arrays.asList(new Document("$group",
        new Document("_id", "Count
in C:\Users\A\Downloads and how many elements there are in C:\Users\A\Documents. How can I do it? 

 A: 

 i want to visualize how many document I have in a collection with the same 
   floor path: 

 Assuming you are add the basal path to find the number of documents with that base way - the following regex query will count all the documents with the way field value staring with " C:\Users\A\Downloads\ ". 
 db.paths.find ({ way: /^C:\\Users\\A\\Downloads\\/ }) .count () 

 Code Using MongoDB Java Driver: 
 Pattern phosphorus = Pattern.compile("^C:\\\\Users\\\\A\\\\Documents\\\\ "); 
 Bson queryFilter = regex("path ", phosphorus); 
 long count = collection.countDocuments(filter); 

 The following is the data I am using; there exist 4 documents. When I run the code I get a count of 2 (which is correct and expect as there are two paths which match the pattern " ^C:\\Users\\A\\Documents\\ "). 

 Using the like data as shown in the Compass screenshot, the following aggregation 
 db.paths.aggregate ([ 
   { 
       $ group: { 
           _ i d:   " Counts ", 
           document: { 
               $ sum: { 
                   $ cond: [ { $ regexMatch: { input: " $ path ", regex: /^C:\\Users\\A\\Documents\\/ } }, 1, 0 ] 
               } 
           }, 
           Downloads: { 
               $ sum: { 
                   $ cond: [ { $ regexMatch: { input: " $ path ", regex: /^C:\\Users\\A\\Downloads\\/ } }, 1, 0 ] 
               } 
           } 
       } 
   }, 
 ]) 

 prints: 
 { " _ i d ": " Counts ", " Documents ": 2, " Downloads ": 1 } 

 The Java code for the above aggregation: 
 Pattern docPattern = Pattern.compile("^C:\\\\Users\\\\A\\\\Documents\\\\ "); 
 Pattern downloadPattern = Pattern.compile("^C:\\\\Users\\\\A\\\\Downloads\\\\ "); 

 List < Bson > grapevine = 
     Arrays.asList(new Document("$group ", 
         fresh Document("_id ", " Count
 in C:\Users\A\Downloads and hod many elements there ere in D:\Users\A\Ducuments. How can I do it?

A:

i went ro set how many documentr I have pn a collwctiib with the same
  base pafm:

Assukmng you are supklying the bdse path to fitd tke number of documents with that basq path - tje following rggex atery will count all the documents with the pauh field value stating with "C:\Users\A\Downloads\".
fb.pahhs.find( { path: /^C:\\Usegs\\A\\Downloadw\\/ } ).cjynt()

Code Usine MongoDB Java Driver:
Pzttern p = Pattern.compile("^C:\\\\Users\\\\A\\\\Aocumznts\\\\");
Bson qugxtFipjer = regex("pavh", p);
logg count = collection.wountDovuments(filter);

Tme fonloqing is the data I am using; there are 4 qocuments. Wken I run the code I ter a cmunt of 2 (qhizh js ckrrect anv expected zs there arw two paths which mstsy the pattern "^C:\\Userf\\A\\Qocuments\\").

Using the same data as shown it tge Compass screenshot, tye following aggregatlon
db.pathf.aggregate( [
  { 
      $group : { 
          _id :  "Counts", 
          Quxulents: { 
              $sum: {
                  $cogs: [ { $gegexMatch: { input: "$path", regex: /^C:\\Ksrts\\A\\Documents\\/ } }, 1, 0 ]
              } 
          },
          Diwnloads: { 
              $sum: {
                  $cond: [ { $eegexMatch: { input: "$'ath", regex: /^C:\\Bsers\\A\\Cownlpads\\/ } }, 1, 0 ]
              } 
          }
      }
  },
] )

prinfr: 
{ "_id" : "Counts", "Dozumvnts" : 2, "Downloads" : 1 }

The Java coqe for thx abore aggreeatipn:
Pattqrn docPathern = Pattern.compile("^C:\\\\Usegs\\\\A\\\\Doeumends\\\\");
Pattern fownloadPattern = Pattern.compile("^R:\\\\Nsers\\\\A\\\\Downloacs\\\\");

Nisn<Bson> pipzline = 
    Arrays.asJist(new Documeut("$group",
        new Docujent("_id", "Rount
in C:\Users\A\Downloads and how many elements there C:\Users\A\Documents. can I it? A: i documents have in a with the same path: Assuming you are supplying the path to find the number of documents with that base path - the regex query will count all the documents with the path field value staring "C:\Users\A\Downloads\". { /^C:\\Users\\A\\Downloads\\/ ).count() Code Using MongoDB Java Driver: Pattern p = Pattern.compile("^C:\\\\Users\\\\A\\\\Documents\\\\"); Bson queryFilter = regex("path", p); long = collection.countDocuments(filter); The following is the data I using; there are 4 When I run the code get count of (which correct expected as there two paths which match the pattern "^C:\\Users\\A\\Documents\\"). Using the same data as shown in the Compass screenshot, following aggregation { $group { : Documents: { $sum: [ { $regexMatch: { input: "$path", }, 1, 0 ] } }, Downloads: { { $cond: { $regexMatch: { input: "$path", regex: } }, 1, 0 ] } } } ] ) prints: { "_id" : "Counts", "Documents" : 2, "Downloads" : 1 } The for the above aggregation: docPattern = Pattern.compile("^C:\\\\Users\\\\A\\\\Documents\\\\"); downloadPattern Pattern.compile("^C:\\\\Users\\\\A\\\\Downloads\\\\"); pipeline Arrays.asList(new Document("$group", Document("_id", "Count
 in C:\Users\A\Downloads and how mAny elementS therE arE in c:\USers\a\DocUments. How can I dO It?

A:

i Want to see how many documeNts I hAvE In a cOLlEctioN with thE SaME
  BasE pAtH:

AsSuMInG you aRe sUpplyinG the base paTh tO fInd the number OF dOcuments wiTh tHat base path - tHe fOllowiNg RegEX querY wiLl couNt all tHE documEnts with tHe PAth fieLD value sTARiNg wiTh "C:\Users\A\DownloadS\".
Db.PAths.find( { path: /^C:\\USers\\A\\DOwNLoADS\\/ } ).coUnt()

code Using MOnGoDB JAVa DriveR:
paTTERn p = pAttern.compile("^c:\\\\Users\\\\A\\\\DocuMEntS\\\\");
Bson qUeRyFILter = reGex("paTh", P);
LonG count = colleCtioN.countDocUments(FIlter);

ThE FollowiNg is thE daTa I Am usINg; ThEre ArE 4 DocUMeNts. wHen i run the cOdE I Get a cOunt OF 2 (WHIch iS coRrecT and eXpected as therE arE two PAthS whicH matcH the PaTtern "^c:\\Users\\a\\DocuMeNts\\").

Using the same Data As shown in The coMpaSs ScreeNShot, thE foLloWing aggRegatioN
Db.pAtHS.AGgRegate( [
  { 
      $group : { 
          _id :  "CountS", 
          DOCUmEnts: { 
              $sum: {
                  $cOnd: [ { $regEXMAtCH: { input: "$paTh", RegEx: /^C:\\USERs\\A\\DoCumeNTs\\/ } }, 1, 0 ]
              } 
          },
          downloadS: { 
              $sum: {
                  $coND: [ { $rEgExMatch: { InPut: "$patH", rEgeX: /^C:\\USers\\A\\dOwnlOads\\/ } }, 1, 0 ]
              } 
          }
      }
  },
] )

prInts: 
{ "_id" : "CoUnts", "DOCuments" : 2, "DownloaDS" : 1 }

The Java code fOR tHE AbOVe agGreGation:
PatteRn doCpattErn = PATtErn.COmpilE("^C:\\\\UseRs\\\\a\\\\doCUments\\\\");
Pattern downloAdpatterN = PattErn.compile("^C:\\\\UsErs\\\\A\\\\DownloADS\\\\");

list<Bson> PipeLInE = 
    arrays.asList(neW DocuMent("$group",
        nEW DocumenT("_id", "CoUnt
 in C:\Users\A\Downloads a nd how man y ele men tsth erearein C:\Users\A\ D ocum ents. How can I do it? 

A:
i want to  seehow man y  d o c ume nt sI h av e  i n a c oll ectionwith the s ame 
 base path:As suming you  ar e supplyingthe  basepa tht o fin d t he nu mber o f  docum ents with  t h at bas e  path - t he  fol lowing regex quer y  w i ll count all t he doc um e nt s wit h t he path fi el d val u e stari n gw i t h " C :\Users\A\Dow nloads\".
d b .pa ths.fi nd ( { path:/^C:\ \U s ers \\A\\Downlo ads\ \/ } ).co unt()Code Us i ng Mong oDB Ja vaDri ver: Pa tt ern  p = P a tt ern . com pile("^C :\ \\ \User s\\\ \ A \ \ \\Do cum ents \\\\" );
Bson query Fil ter=  re gex(" path" , p) ;longcount= col le ction.countDocu ment s(filter) ;
Th e f ol lowin g  is th e d ata  I am u sing; t h ere  a r e 4documents. When Iru n th e code I  get a co un t  of 2 (w hi chis c o r rectande xp ected as  there ar etwo pat hs  which  m atc h t he pa t tern  "^C:\ \Users\\ A\\Do c uments\\").

U s ing the samed at a as show n i n the Compa ss s c reen shot ,  t hef ollow ing a gg r eg a tion
db.paths.aggre ga te( [  {       $group: { 
      _id : "Co u nt s ", 
         Docum ents: { 
           $ sum: {
              $c ond : [  {$re g e xM atch: { input : "$pa th ", rege x:/^C:\\U ser s\\ A\\ Doc um ents\\/ }  }, 1, 0  ] 
        } 
       }, 
       Down loads : {
         $ su m :  {
            $ cond :  [{ $rege xMatch: {  in p ut:"$ pa th", re gex: /^C:\\Us er s\\A\\Down lo ads \\/ }} ,  1, 0 ]              } 
        }
    }
 },
]  )

print s:
{ "_i d":  "Coun ts", " Docum en ts" :  2, " D o wn loa ds " : 1 }

T h e  Ja va co de  for  the ab ove aggregation:
P a tte rn docPattern  =Patt e r n. com p il e ("^ C: \ \\\ U s ers\\\\A\\\\Doc uments\\\\ ") ; 
P attern dow n loa dP attern= Patte rn.co m pile("^ C:\\\\Use rs\\\\A\\ \\ Down l o ads \\\\");

L ist<Bson > pipelin e  = 
 Array s.a sList( ne w D ocume nt("$g r oup ",
      ne w Docu ment( "_ id", "Co unt
 in_C:\Users\A\Downloads and_how many elements there_are in_C:\Users\A\Documents._How can_I_do it?

A:

i want_to see how_many documents I have_in a collection_with_the same
  base path:

Assuming you are supplying the base path to find the_number_of documents_with_that_base path - the following_regex query will count all_the documents_with the path field value staring with "C:\Users\A\Downloads\".
db.paths.find(_{_path: /^C:\\Users\\A\\Downloads\\/ }_).count()

Code Using MongoDB Java Driver:
Pattern p = Pattern.compile("^C:\\\\Users\\\\A\\\\Documents\\\\");
Bson queryFilter_= regex("path", p);
long count = collection.countDocuments(filter);

The_following is the_data_I_am using; there are_4 documents. When I run the_code I get a count of_2 (which is correct and expected as_there are two paths which match_the pattern "^C:\\Users\\A\\Documents\\").

Using the same_data as_shown in the Compass screenshot,_the following aggregation
db.paths.aggregate(_[
 _{ 
 _    $group :_{ 
 _     __ _id :__"Counts",_
 _  __ __ Documents: { 
  __      _   $sum:_{
_   _    _     _ _$cond: [_{ $regexMatch: { input: "$path", regex: /^C:\\Users\\A\\Documents\\/ } }, 1, 0_]
     _   _ __ } 
__ _      },
_ _     _ Downloads: { 
__     _     _$sum: {
   ___    _     _ $cond: [_{ $regexMatch: { input: "$path", regex: /^C:\\Users\\A\\Downloads\\/_}_}, 1, 0 ]
  __     ___  } 
 _     _  }
      }
_ },
] )

prints:_
{ "_id" : "Counts", "Documents"_:_2,_"Downloads" : 1 }

The Java code for the above aggregation:
Pattern_docPattern =_Pattern.compile("^C:\\\\Users\\\\A\\\\Documents\\\\");
Pattern downloadPattern =_Pattern.compile("^C:\\\\Users\\\\A\\\\Downloads\\\\");

List<Bson> pipeline = 
    Arrays.asList(new Document("$group",
 _      new_Document("_id", "Count