What are some ways that we can export "post" from wp (of mysql) to mongodb for nodebb blogs programmatically?
-
Hello all,
trying to move all my wp blogs into nodebb blogs, what are some ways we can do programmatically? (just leaned about mongodb as installed nodebb, so far understand that everything seem like saved in a object)given example from the form
db.objects.update({_key:"user:1"}, {$set: {"reputation": 2}}); db.objects.update({_key:"users:reputation", "value": "1"}, {$set: {"score": 2}});
How can we export wp post, then into nodebb blogs programmatically?
Thank you. -
Instead of trying to do it via database queries it would be easier if you wrote some javascript and use the nodebb function
topics.post
and pass in the required data. That would create a topic in the specified category with all the necessary entries in the database.A custom script looks like below, you place it into the same folder as
config.json
and run it withnode my_script
. The script can use any api from nodebb./* globals require, console, process */ 'use strict'; const nconf = require('nconf'); nconf.file({ file: 'config.json', }); nconf.defaults({ base_dir: __dirname, views_dir: './build/public/templates', upload_path: 'public/uploads', }); const db = require('./src/database'); db.init(async (err) => { const meta = require('./src/meta'); await meta.configs.init(); if (err) { console.log(`NodeBB could not connect to your database. Error: ${err.message}`); process.exit(); } await postTopic(); console.log('done'); process.exit(); }); async function postTopic() { const topics = require('./src/topics'); // TODO: read blog post data from WP // create a nodebb topic await topics.post({ cid: 1, uid: 1, title: 'some title', content: 'content of post' }); }
Modify the script and set the correct
cid
anduid
. -
here is the code that I am trying to make it work, please help.
client = MongoClient(f"mongodb://{username}:{password}@{host}:{port}/{database_name}") db = client[database_name] collection = db[collection_name] my_object = { '_id': ObjectId(), '_key': 'post:5', 'content': 'testing', 'pid': 5, 'tid': 4, 'timestamp': time.time() * 1000, # convert current time to milliseconds 'uid': 2 } collection = db['nodebb'] collection.insert_one(my_object)
-
Instead of trying to do it via database queries it would be easier if you wrote some javascript and use the nodebb function
topics.post
and pass in the required data. That would create a topic in the specified category with all the necessary entries in the database.A custom script looks like below, you place it into the same folder as
config.json
and run it withnode my_script
. The script can use any api from nodebb./* globals require, console, process */ 'use strict'; const nconf = require('nconf'); nconf.file({ file: 'config.json', }); nconf.defaults({ base_dir: __dirname, views_dir: './build/public/templates', upload_path: 'public/uploads', }); const db = require('./src/database'); db.init(async (err) => { const meta = require('./src/meta'); await meta.configs.init(); if (err) { console.log(`NodeBB could not connect to your database. Error: ${err.message}`); process.exit(); } await postTopic(); console.log('done'); process.exit(); }); async function postTopic() { const topics = require('./src/topics'); // TODO: read blog post data from WP // create a nodebb topic await topics.post({ cid: 1, uid: 1, title: 'some title', content: 'content of post' }); }
Modify the script and set the correct
cid
anduid
. -
Hi @baris
Q1. As post created, is this expected ?node my_script.js [winston] Attempt to write logs with no transports, which can increase memory usage: {"message":"[minifier] utilizing a maximum of 3 additional threads","level":"verbose"} done
Q2, How to gives tags as posting?
As trying adding the tags field, it gives error as:[winston] Attempt to write logs with no transports, which can increase memory usage: {"message":"[minifier] utilizing a maximum of 3 additional threads","level":"verbose"} /home/pi/nodebb/src/topics/tags.js:68 throw new Error('[[error:invalid-data]]'); ^ Error: [[error:invalid-data]] at Topics.validateTags (/home/pi/nodebb/src/topics/tags.js:68:10) at Object.wrapperCallback [as validateTags] (/home/pi/nodebb/src/promisify.js:46:11) at Topics.post (/home/pi/nodebb/src/topics/create.js:89:16) at async postTopic (/home/pi/nodebb/my_script.js:36:2) at async /home/pi/nodebb/my_script.js:27:2 Node.js v18.14.1
with code :
await topics.post({ cid: 3, uid: 1, tid: 11, tags: 'nodebb', title: 'some title some title some title', content: 'content of post content of post content of post' });
Thank you.
-