ยง2024-12-14

(PY-3.10.15-R-4.4) alexlai@ApiServer:~$ conda install -c conda-forge r-mongolite  
...
  added / updated specs:
    - r-mongolite


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    certifi-2024.8.30          |     pyhd8ed1ab_0         160 KB  conda-forge
    cyrus-sasl-2.1.27          |       h54b06d7_7         214 KB  conda-forge
    libntlm-1.4                |    h7f98852_1002          32 KB  conda-forge
    r-askpass-1.2.1            |    r44h2b5f3a1_0          31 KB  conda-forge
    r-jsonlite-1.8.9           |    r44h2b5f3a1_0         621 KB  conda-forge
    r-mime-0.12                |    r44hb1dbf0f_3          52 KB  conda-forge
    r-mongolite-2.8.2          |    r44h2b5f3a1_0         581 KB  conda-forge
    r-openssl-2.2.2            |    r44he8289e2_0         676 KB  conda-forge
    r-sys-3.4.3                |    r44h2b5f3a1_0          49 KB  conda-forge
    ------------------------------------------------------------
                                           Total:         2.4 MB

The following NEW packages will be INSTALLED:

  cyrus-sasl         conda-forge/linux-64::cyrus-sasl-2.1.27-h54b06d7_7 
  libntlm            conda-forge/linux-64::libntlm-1.4-h7f98852_1002 
  r-askpass          conda-forge/linux-64::r-askpass-1.2.1-r44h2b5f3a1_0 
  r-jsonlite         conda-forge/linux-64::r-jsonlite-1.8.9-r44h2b5f3a1_0 
  r-mime             conda-forge/linux-64::r-mime-0.12-r44hb1dbf0f_3 
  r-mongolite        conda-forge/linux-64::r-mongolite-2.8.2-r44h2b5f3a1_0 
  r-openssl          conda-forge/linux-64::r-openssl-2.2.2-r44he8289e2_0 
  r-sys              conda-forge/linux-64::r-sys-3.4.3-r44h2b5f3a1_0 

The following packages will be SUPERSEDED by a higher-priority channel:

  certifi            pkgs/main/linux-64::certifi-2024.8.30~ --> conda-forge/noarch::certifi-2024.8.30-pyhd8ed1ab_0 


Proceed ([y]/n)? y

(PY-3.10.15-R-4.4) alexlai@ApiServer:~$ R                                                                                                                                    
...
> library(mongolite)

> ysMongoV8 <- "mongodb://siteRootAdmin:b23258585@ysmongov801.yushei.com.tw:27017,ysmongov802.yushei.com.tw:27017,ysmongov803.yushei.com.tw:27017/?replicaSet=ys20241107&authSource=admin"
> car_in_out_collection <- mongo(collection = "car_in_out", db = "YuSheiDB", url = ysMongoV8)
> car_in_out_collection$count()
[1] 490788
> car_in_out_collection$iterate()$one()
$plateText
[1] "BMH5561"

$inTime
[1] "2024-03-31T21:41:05"

$outTime
[1] "2024-03-31T23:42:37"

$carType
[1] "car"

$inCameraSource
[1] ""

$isExit
[1] TRUE

$isMonthlyCar
[1] FALSE

$isUserCreate
[1] FALSE

$outCameraSource
[1] ""

ysMongoV8 <- "mongodb://siteRootAdmin:b23258585@ysmongov801.yushei.com.tw:27017,ysmongov802.yushei.com.tw:27017,ysmongov803.yushei.com.tw:27017/?replicaSet=ys20241107&authSource=admin"

car_in_out_collection <- mongo(collection = "car_in_out", db = "YuSheiDB", url = ysMongoV8)


# This is the connection_string. You can get the exact url from your MongoDB cluster screen
connection_string = 'mongodb+srv://<username>:<password>@<cluster-name>.mongodb.net/sample_training'
trips_collection = mongo(collection="trips", db="sample_training", url=connection_string)

    

ysMongoV8= "mongodb+srv://siteRootAdmin:b23258585@ysmongov801.yushei.com.tw:27017,ysmongov802.yushei.com.tw:27017,ysmongov803.yushei.com.tw:27017/?replicaSet=ys20241107&authSource=admin"

car_in_out_collection= mongo(collection="car_in_out", db="YuSheiDB", url=ysMongoV8)

    Connect to a MongoDB collection
mongo <- mongo(collection = "test", db = "mydatabase", url = "mongodb://localhost")

# Insert a data frame
mongo$insert(data.frame(name = "Alice", age = 25))

# Query the data
print(mongo$find('{}'))


mongodb://ysadmin:yushei23258585@ysmongov801.yushei.com.tw:27017,ysmongov802.yushei.com.tw:27017,ysmongov803.yushei.com.tw:27017/YuSheiDB?replicaSet=ys20241107'


Environment="MONGO_URL=mongodb://siteRootAdmin:b23258585@ysmongov801.yushei.com.tw:27017,ysmongov802.yushei.com.tw:27017,ysmongov803.yushei.com.tw:27017/Dragonfly28V803?replicaSet=ys20241107&authSource=admin"
Environment="MONGO_OPLOG_URL=mongodb://siteRootAdmin:b23258585@ysmongov801.yushei.com.tw:27017,ysmongov802.yushei.com.tw:27017,ysmongov803.yushei.com.tw:27017/Dragonfly28V803?replicaSet=ys20241107&authSource=admin"

{ _id: ObjectId('6715b7bff679da3f6e2a7f26'), plateText: 'BMH5561', inTime: '2024-03-31T21:41:05', outTime: '2024-03-31T23:42:37', carType: 'car', inCameraSource: '', isExit: true, isMonthlyCar: false, isUserCreate: false, outCameraSource: '' },

ys20241107 [primary] YuSheiDB> db.car_in_out.find().sort({_id: -1}).limit(2) [ { _id: ObjectId('675d2bcc118e03ee0709362d'), plateText: 'ALR9326', inTime: '2024-12-14T12:40:15', carType: 'car', inCameraSource: '003', outTime: '2024-12-14T15:09:59', isExit: false, isMonthlyCar: false, isUserCreate: false }, { _id: ObjectId('675d2bac118e03ee0709359c'), plateText: 'MEE8000', inTime: '2024-12-14T13:30:29', carType: 'motor', inCameraSource: '001', outTime: '2024-12-14T15:09:59', isExit: false, isMonthlyCar: false, isUserCreate: false } ]