Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
codemirror-mongodb
Advanced tools
Readme
Use CodeMirror with MongoDB.
https://mongodb-js.github.io/codemirror-mongodb
I recently took on the project of rewriting the query input for MongoDB Compass. It’s a real pain when writing queries to have to keep the query language and the shape of the data you’re querying against in your working memory. MongoDB users have more important work to do.
Autocompletion for field names is a feature request we hear a lot at MongoDB. We have a sketch in Compass of what the schema probably looks like. Leveraging schema analysis to enable autocompletion is a feature we’ve been wanting to build for a long time.
After weighing my options and researching the existing libraries I could potentially use, I kept coming back to one, CodeMirror.
CodeMirror is the defacto open-source code editor. CodeMirror is used in the devtools for Firefox, Chrome, and Safari, in Light Table, Adobe Brackets, Bitbucket, and over 100 other projects.
var CodeMirror = require('codemirror');
require('codemirror-mongodb/addon/hint/mongodb-hint');
CodeMirror.fromTextArea(document.getElementById('oneliner'), {
lineNumbers: false,
scrollbarStyle: 'null',
mode: 'javascript',
autoCloseBrackets: true,
matchBrackets: true,
theme: 'mongodb',
extraKeys: {
'Ctrl-Space': 'autocomplete',
'Shift-Enter': 'parse'
},
mongodb: {
fields: {
_id: 'ObjectId',
name: 'String',
age: 'Number',
number_of_pets: 'Number',
addresses: 'Array',
'addresses.street': 'String'
}
}
}).on('beforeChange', function formatAsSingleLine(cm, change) {
if (change.update) {
var newtext = change.text.join('').replace(/\n/g, '');
change.update(change.from, change.to, [newtext]);
}
return true;
});
var React = require('react');
var CodeMirror = require('react-codemirror');
require('codemirror-mongodb/addon/hint/mongodb-hint');
var App = React.createClass({
getInitialState: function() {
return {
code: "{}",
};
},
updateCode: function(newCode) {
this.setState({
code: newCode.replace(/\n/g, ''),
});
},
render: function() {
const options = {
lineNumbers: false,
scrollbarStyle: 'null',
mode: 'javascript',
autoCloseBrackets: true,
matchBrackets: true,
theme: 'mongodb',
extraKeys: {
'Ctrl-Space': 'autocomplete'
},
mongodb: {
fields: {
_id: 'ObjectId',
name: 'String',
age: 'Number',
number_of_pets: 'Number',
addresses: 'Array',
'addresses.street': 'String'
}
}
};
return <CodeMirror value={this.state.code} onChange={this.updateCode} options={options} />
}
});
React.render(<App />, document.getElementById('app'));
█
below is the user cursor position when autocomplete triggered
or the resulting cursor position when a completion is applied.
Current schema of the selected namespace is:
var fields = {
_id: 'ObjectId',
name: 'String',
age: 'Number',
number_of_pets: 'Number'
};
${fieldPath}
A completion for v1${fieldPath}: █
Maybe nice to add in the futureInput {█}
Completions
_id
name
age
number_of_pets
Input {_id█}
Completions
_id
_id: ObjectId("█")
Input {n█}
2 matching fields
Completions
name
number_of_pets
Input {na█}
1 matching field so show extended
Completions
name
name: █
with startername: "█"
open exact matchname: /^█/
open prefix regexInput {name█}
Still 1 matching field so show extended
Completions
name
name: █
with startername: "█"
open exact matchname: /^█/
open prefix regexInput {name: █}
Completions
█
with starter"█"
open exact match/^█/
open prefix regexInput {name: {█}}
Completions
$gte
$gt
$lte
$lt
$eq
$ne
$type
$size
$exists
$exists: false
field not set$exists: true
field is set$in
$in: ["█"]
for strings, $in: [█]
for numbers$nin
$nin: ["█"]
for strings, n$in: [█]
for numbers$all
{text, displayText, and className}
instead of just stringsObject("█")
Apache 2.0
FAQs
Use CodeMirror with MongoDB.
The npm package codemirror-mongodb receives a total of 49 weekly downloads. As such, codemirror-mongodb popularity was classified as not popular.
We found that codemirror-mongodb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 27 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.