用于桌面应用程序的本地 NoSQL 数据库

Local NoSQL database for desktop application

是否有类似于 Sqlite 的桌面应用程序的 NoSQL 数据库解决方案,其中数据库是用户计算机上的文件?该数据库将由桌面上使用的 nodejs 应用程序调用。

我使用 mongodb 本地实例。它非常容易设置。这是一个简单的设置指南 MongoDB

你也可以试试couchdb。有一个例子连同 electron

http://blog.couchbase.com/build-a-desktop-app-with-github-electron-and-couchbase

我看到这是一个老问题,但对您来说,一个较新的选择是 AceBase,它是一个快速、低内存、事务性、支持索引和查询的 NoSQL 数据库引擎和服务器 node.js 和浏览器。绝对是 SQLite 的一个很好的 NoSQL 替代品,并且非常易于使用:

const { AceBase } = require('acebase');
const db = new AceBase('mydb');

// Add question to database:
const questionRef = await db.ref('Whosebug/questions').push({ 
   title: 'Local NoSQL database for desktop application',
   askedBy: 'tt9',
   date: new Date(),
   question: 'Is there a NoSQL database solution for desktop applications similar to Sqlite where the database is a file on the user\'s machine? ..'
});

// questionRef is now a reference to the saved database path,
// eg: "Whosebug/questions/ky9v13mr00001s7b829tmwk1"

// Add my answer to it:
const answerRef = await questionRef.child('answers').push({
   text: 'Use AceBase!'
});

// answerRef is now reference to the saved answer in the database, 
// eg: "Whosebug/questions/ky9v13mr00001s7b829tmwk1/answers/ky9v5atd0000eo7btxid7uic"

// Load the question (and all answers) from the database:
const questionSnapshot = await questionRef.get();

// A snapshot contains the value and relevant metadata, such as the used reference:
console.log(`Got question from path "${questionSnapshot.ref.path}":`, questionSnapshot.val());

// We can also monitor data changes in realtime
// To monitor new answers being added to the question:
questionRef.child('answers').on('child_added').subscribe(newAnswerSnapshot => {
   console.log(`A new answer was added:`, newAnswerSnapshot.val());
});

// Monitor any answer's number of upvotes:
answerRef.child('upvotes').on('value').subscribe(snapshot => {
   const prevValue = snapshot.previous();
   const newValue = snapshot.val();
   console.log(`The number of upvotes changed from ${prevValue} to ${newValue}`);
});

// Updating my answer text:
await answerRef.update({ text: 'I recommend AceBase!' });

// Or, using .set on the text itself:
await answerRef.child('text').set('I can really recommend AceBase');

// Adding an upvote to my answer using a transaction:
await answerRef.child('upvotes').transaction(snapshot => {
   let upvotes = snapshot.val();
   return upvotes + 1; // Return new value to store
});

// Query all given answers sorted by upvotes:
let querySnapshots = await questionRef.child('answers')
   .query()
   .sort('upvotes', false) // descending order, most upvotes first
   .get();

// Limit the query results to the top 10 with "AceBase" in their answers:
querySnapshots = await questionRef.child('answers')
   .query()
   .filter('text', 'like', '*AceBase*')
   .take(10)
   .sort('upvotes', false) // descending order, most upvotes first
   .get();

// We can also load the question in memory and make it "live":
// The in-memory value will automatically be updated if the database value changes, and
// all changes to the in-memory object will automatically update the database:

const questionProxy = await questionRef.proxy();
const liveQuestion = questionProxy.value;

// Changing a property updates the database automatically:
liveQuestion.tags = ['node.js','database','nosql'];

// ... db value of tags is updated in the background ...

// And changes to the database will update the liveQuestion object:
let now = new Date();
await questionRef.update({ edited: now });

// In the next tick, the live proxy value will have updated:
process.nextTick(() => {
   liveQuestion.edited === now; // true
});

我希望这对阅读本文的任何人有所帮助,AceBase 是这个街区的一个相当新的孩子,开始掀起波澜!

请注意,AceBase 还能够 运行 在浏览器中,并作为具有完整身份验证和授权选项的远程数据库服务器。可与服务器和其他客户端实时同步,掉线后重连。

有关更多信息和文档,请查看 AceBase at GitHub

如果你想快速尝试上面的例子,你可以copy/paste在RunKit编辑器中输入代码:https://npm.runkit.com/acebase