- we can have multiple versions of MongodDB installed on Mac. Follow the tutorial below:
https://www.mongodb.com/docs/v5.0/tutorial/install-mongodb-on-os-x/ - Switch version by
brew services stop mongodb-community@5.01
then start another one, for example: @6.0 - mongodrestore with drop will not create the indexes.
- mongodrestore without drop will not update the records with the same _id
- so maybe just delete the database and run mongodbrestore with drop? I do this LOCAL ONLY
- aggregation $firstN is a new feature for mongod5.3+, and only Mongod5.0 can be installed locally, other rapid version need MongoAtlas. https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/
- if target db version is higher than source, mongorestore could fail.
梵总 发布的帖子
-
a few things I learn about mongodb
-
Intresting - insertOne added _id to the input data
https://jira.mongodb.org/browse/NODE-1160
before: storkeData = {a: 1, b: 2}targetColl.insertOne(strokeData)
after: strokeData={a:1, b:2, _id: new ObjectId("639545affd84671b2a7f26ea")}
To avoid, we can add "forceServerObjectId", like:
targetColl.insertOne(strokeData, {forceServerObjectId: true})
-
RE: Chatjs Q&A
chatjs doc should be a good place to find answer:
https://www.chartjs.org/docs/latest/axes/cartesian/category.htmlhopefully!
-
Chatjs Q&A
// Axis Type - Linear/Category/Time. etc. To use them we have to import them and register them
https://stackoverflow.com/questions/70777779/time-series-line-chart-js-in-react-not-working
// how to display datetime:
https://stackoverflow.com/questions/53669361/how-to-display-date-as-label-on-x-axis-in-chart-js// If two sets of data have different x-axis, we should not share labels, instead, create the dataset using [{x1,y1}{x2,y2}...]
https://stackoverflow.com/questions/61062420/how-to-skip-labels-of-a-line-in-multiline-graph-in-chartjs -
group by & count array of objects
const allPubs = rows.reduce((ac, item) => {
const idx = ac.findIndex((x) => x.publicationName === item.publicationName);
console.log("IDX", idx);
if (idx === -1) {
ac.push(item);
} else {
ac[idx].publicationQty += item.publicationQty;
}
return ac;
}, []);const sortedRows = orderBy(allPubs, ["publicationQty"], ["desc"]);
-
RE: write to Excel on the client side
const xslsHeaders = [type, "Total", "Percentage"]; const sheetData = [[type, "", ""], [dateRange, "", ""], xslsHeaders, ...main]; onClick={() => exportFile(`${type} ${dateRange}`, sheets)}
-
Fix Href Interpolation Failed error
https://nextjs.org/docs/messages/href-interpolation-failed
const handlePaginationChange = async (value) => { // await fetchRecords(scope, value - 1); // setActivePage(value); const params = { pathname: "/clubs/[slug]", query: { slug: lsc, page: value }, }; router.push(params, undefined, { shallow: true }); window && window.scroll({ top: 0, behavior: "smooth" }); };
-
start serverless with different port
"its": "sls offline start --stage=localits --noAuth --noTimeout --httpPort=4000 --lambdaPort=4002"
-
use Env variable in public.html for create react app
<script type="text/javascript"> console.log("CODEBUILDNUMBER: ", "%REACT_APP_CODEBUILD_BUILD_ID%"); // code build number if any console.log("%NODE_ENV%"); // development </script>
-
remote access to your WSL
Great tutorial:
https://www.illuminiastudios.com/dev-diaries/ssh-on-windows-subsystem-for-linux/In my case, the WSL should be on the main network, i.e. 192.168.1., not on the subNetwork like mesh wifi network, ex: 192.168.4. (which is a subnetwork of the mesh network 192.168.1.*)
-
PHP is not a good language talking to MongoDB
It's just too hard. Even for finding a doc. Found this live saver:
The BSONDocument object has a jsonSerialize method. Use that: Example {"_id" : 12345, "filename" : "myfile", "header" : { "version" : 2, "registry" : "test", "serial" : 20080215, "records" : 17806, "startDate" : 19850701, "endDate" : 20080214 }, } $connect = new MongoDB\Client('mongodb://yourconnection'); $db = $connect->YourDB; $collection = $db->YourCollection; $test = $collection->findOne(array("_id"=>12345)); $data = $test->jsonSerialize(); echo $data->_id; echo $data->filename; Will output this: 12345 myfile